Completed
Pull Request — develop (#1576)
by Naveen
01:06
created
src/modules/pods/includes/Schema.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -4,101 +4,101 @@
 block discarded – undo
4 4
 
5 5
 class Schema {
6 6
 
7
-	public function get_context_type() {
8
-
9
-		if ( isset( $_REQUEST['post'] ) || isset($_REQUEST['post_ID']) ) {
10
-			return Context::POST;
11
-		}
12
-		if ( isset( $_REQUEST['tag_ID'] ) ) {
13
-			return Context::TERM;
14
-		}
15
-
16
-		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
17
-			return Context::ADMIN_AJAX;
18
-		}
19
-
20
-		return Context::UNKNOWN;
21
-	}
22
-
23
-
24
-	/**
25
-	 * @return Context
26
-	 */
27
-	public function get() {
28
-		// we need to identify the context to filter the results.
29
-
30
-		$identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) )
31
-			: sanitize_text_field( wp_unslash( $_REQUEST['post_ID'] ) );
32
-
33
-		if ( $identifier ) {
34
-			// If post identifier, get schema.
35
-			return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) );
36
-		}
37
-
38
-		$identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : '';
39
-
40
-		if ( $identifier ) {
41
-			// If post identifier, get schema.
42
-			return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) );
43
-		}
44
-
45
-		if ( is_admin() && defined( 'DOING_AJAX' ) ) {
46
-			return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() );
47
-		}
48
-
49
-		return new Context( Context::UNKNOWN, null, null );
50
-
51
-	}
52
-
53
-	/**
54
-	 * @return Schema_Field_Group[]
55
-	 */
56
-	private function get_fields_for_post( $identifier ) {
57
-		$types          = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier );
58
-		$schema_classes = \Wordlift_Schema_Service::get_instance();
59
-
60
-		return array_map(
61
-			function ( $schema_type ) use ( $schema_classes ) {
62
-				$data = $schema_classes->get_schema( strtolower( $schema_type ) );
63
-
64
-				return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
65
-			},
66
-			$types
67
-		);
68
-	}
69
-
70
-	/**
71
-	 * @return Schema_Field_Group[]
72
-	 */
73
-	private function get_fields_for_term( $identifier ) {
74
-		$term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
75
-		$schema_classes    = \Wordlift_Schema_Service::get_instance();
76
-
77
-		return array_map(
78
-			function ( $schema_type ) use ( $schema_classes ) {
79
-				$data = $schema_classes->get_schema( strtolower( $schema_type ) );
80
-
81
-				return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
82
-			},
83
-			$term_entity_types
84
-		);
85
-	}
86
-
87
-	private function get_all_fields() {
88
-		$schema_classes   = \Wordlift_Schema_Service::get_instance();
89
-		$all_schema_slugs = $schema_classes->get_all_schema_slugs();
90
-
91
-		return array_filter(
92
-			array_map(
93
-				function ( $schema_type ) use ( $schema_classes ) {
94
-					$data = $schema_classes->get_schema( strtolower( $schema_type ) );
95
-
96
-					return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
97
-				},
98
-				$all_schema_slugs
99
-			)
100
-		);
101
-	}
7
+    public function get_context_type() {
8
+
9
+        if ( isset( $_REQUEST['post'] ) || isset($_REQUEST['post_ID']) ) {
10
+            return Context::POST;
11
+        }
12
+        if ( isset( $_REQUEST['tag_ID'] ) ) {
13
+            return Context::TERM;
14
+        }
15
+
16
+        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
17
+            return Context::ADMIN_AJAX;
18
+        }
19
+
20
+        return Context::UNKNOWN;
21
+    }
22
+
23
+
24
+    /**
25
+     * @return Context
26
+     */
27
+    public function get() {
28
+        // we need to identify the context to filter the results.
29
+
30
+        $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) )
31
+            : sanitize_text_field( wp_unslash( $_REQUEST['post_ID'] ) );
32
+
33
+        if ( $identifier ) {
34
+            // If post identifier, get schema.
35
+            return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) );
36
+        }
37
+
38
+        $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : '';
39
+
40
+        if ( $identifier ) {
41
+            // If post identifier, get schema.
42
+            return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) );
43
+        }
44
+
45
+        if ( is_admin() && defined( 'DOING_AJAX' ) ) {
46
+            return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() );
47
+        }
48
+
49
+        return new Context( Context::UNKNOWN, null, null );
50
+
51
+    }
52
+
53
+    /**
54
+     * @return Schema_Field_Group[]
55
+     */
56
+    private function get_fields_for_post( $identifier ) {
57
+        $types          = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier );
58
+        $schema_classes = \Wordlift_Schema_Service::get_instance();
59
+
60
+        return array_map(
61
+            function ( $schema_type ) use ( $schema_classes ) {
62
+                $data = $schema_classes->get_schema( strtolower( $schema_type ) );
63
+
64
+                return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
65
+            },
66
+            $types
67
+        );
68
+    }
69
+
70
+    /**
71
+     * @return Schema_Field_Group[]
72
+     */
73
+    private function get_fields_for_term( $identifier ) {
74
+        $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
75
+        $schema_classes    = \Wordlift_Schema_Service::get_instance();
76
+
77
+        return array_map(
78
+            function ( $schema_type ) use ( $schema_classes ) {
79
+                $data = $schema_classes->get_schema( strtolower( $schema_type ) );
80
+
81
+                return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
82
+            },
83
+            $term_entity_types
84
+        );
85
+    }
86
+
87
+    private function get_all_fields() {
88
+        $schema_classes   = \Wordlift_Schema_Service::get_instance();
89
+        $all_schema_slugs = $schema_classes->get_all_schema_slugs();
90
+
91
+        return array_filter(
92
+            array_map(
93
+                function ( $schema_type ) use ( $schema_classes ) {
94
+                    $data = $schema_classes->get_schema( strtolower( $schema_type ) );
95
+
96
+                    return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
97
+                },
98
+                $all_schema_slugs
99
+            )
100
+        );
101
+    }
102 102
 
103 103
 
104 104
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
6 6
 
7 7
 	public function get_context_type() {
8 8
 
9
-		if ( isset( $_REQUEST['post'] ) || isset($_REQUEST['post_ID']) ) {
9
+		if (isset($_REQUEST['post']) || isset($_REQUEST['post_ID'])) {
10 10
 			return Context::POST;
11 11
 		}
12
-		if ( isset( $_REQUEST['tag_ID'] ) ) {
12
+		if (isset($_REQUEST['tag_ID'])) {
13 13
 			return Context::TERM;
14 14
 		}
15 15
 
16
-		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
16
+		if (is_admin() && ! defined('DOING_AJAX')) {
17 17
 			return Context::ADMIN_AJAX;
18 18
 		}
19 19
 
@@ -27,41 +27,41 @@  discard block
 block discarded – undo
27 27
 	public function get() {
28 28
 		// we need to identify the context to filter the results.
29 29
 
30
-		$identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) )
31
-			: sanitize_text_field( wp_unslash( $_REQUEST['post_ID'] ) );
30
+		$identifier = isset($_REQUEST['post']) ? sanitize_text_field(wp_unslash($_REQUEST['post']))
31
+			: sanitize_text_field(wp_unslash($_REQUEST['post_ID']));
32 32
 
33
-		if ( $identifier ) {
33
+		if ($identifier) {
34 34
 			// If post identifier, get schema.
35
-			return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) );
35
+			return new Context(Context::POST, $identifier, $this->get_fields_for_post($identifier));
36 36
 		}
37 37
 
38
-		$identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : '';
38
+		$identifier = isset($_REQUEST['tag_ID']) ? sanitize_text_field(wp_unslash($_REQUEST['tag_ID'])) : '';
39 39
 
40
-		if ( $identifier ) {
40
+		if ($identifier) {
41 41
 			// If post identifier, get schema.
42
-			return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) );
42
+			return new Context(Context::TERM, $identifier, $this->get_fields_for_term($identifier));
43 43
 		}
44 44
 
45
-		if ( is_admin() && defined( 'DOING_AJAX' ) ) {
46
-			return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() );
45
+		if (is_admin() && defined('DOING_AJAX')) {
46
+			return new Context(Context::ADMIN_AJAX, null, $this->get_all_fields());
47 47
 		}
48 48
 
49
-		return new Context( Context::UNKNOWN, null, null );
49
+		return new Context(Context::UNKNOWN, null, null);
50 50
 
51 51
 	}
52 52
 
53 53
 	/**
54 54
 	 * @return Schema_Field_Group[]
55 55
 	 */
56
-	private function get_fields_for_post( $identifier ) {
57
-		$types          = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier );
56
+	private function get_fields_for_post($identifier) {
57
+		$types          = \Wordlift_Entity_Type_Service::get_instance()->get_names($identifier);
58 58
 		$schema_classes = \Wordlift_Schema_Service::get_instance();
59 59
 
60 60
 		return array_map(
61
-			function ( $schema_type ) use ( $schema_classes ) {
62
-				$data = $schema_classes->get_schema( strtolower( $schema_type ) );
61
+			function($schema_type) use ($schema_classes) {
62
+				$data = $schema_classes->get_schema(strtolower($schema_type));
63 63
 
64
-				return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
64
+				return new Schema_Field_Group($schema_type, $data['custom_fields']);
65 65
 			},
66 66
 			$types
67 67
 		);
@@ -70,15 +70,15 @@  discard block
 block discarded – undo
70 70
 	/**
71 71
 	 * @return Schema_Field_Group[]
72 72
 	 */
73
-	private function get_fields_for_term( $identifier ) {
74
-		$term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
73
+	private function get_fields_for_term($identifier) {
74
+		$term_entity_types = get_term_meta((int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
75 75
 		$schema_classes    = \Wordlift_Schema_Service::get_instance();
76 76
 
77 77
 		return array_map(
78
-			function ( $schema_type ) use ( $schema_classes ) {
79
-				$data = $schema_classes->get_schema( strtolower( $schema_type ) );
78
+			function($schema_type) use ($schema_classes) {
79
+				$data = $schema_classes->get_schema(strtolower($schema_type));
80 80
 
81
-				return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
81
+				return new Schema_Field_Group($schema_type, $data['custom_fields']);
82 82
 			},
83 83
 			$term_entity_types
84 84
 		);
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
 
91 91
 		return array_filter(
92 92
 			array_map(
93
-				function ( $schema_type ) use ( $schema_classes ) {
94
-					$data = $schema_classes->get_schema( strtolower( $schema_type ) );
93
+				function($schema_type) use ($schema_classes) {
94
+					$data = $schema_classes->get_schema(strtolower($schema_type));
95 95
 
96
-					return new Schema_Field_Group( $schema_type, $data['custom_fields'] );
96
+					return new Schema_Field_Group($schema_type, $data['custom_fields']);
97 97
 				},
98 98
 				$all_schema_slugs
99 99
 			)
Please login to merge, or discard this patch.
src/modules/pods/includes/WlEntityField/Filters.php 2 patches
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -8,200 +8,200 @@
 block discarded – undo
8 8
 
9 9
 class Filters {
10 10
 
11
-	const FIELD_NAME = 'wlentity';
12
-
13
-	public function __construct() {
14
-
15
-		pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) );
16
-		add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 );
17
-		add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 );
18
-		add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 );
19
-		add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 );
20
-		add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 );
21
-
22
-		add_action(
23
-			'pods_meta_save_taxonomy',
24
-			function ( $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ) {
25
-				$this->save_field( 'term', $term_id, $groups );
26
-			},
27
-			10,
28
-			8
29
-		);
30
-
31
-		add_action(
32
-			'pods_meta_save_post',
33
-			function ( $data, $pod, $id, $groups ) {
34
-				$this->save_field( 'post', $id, $groups );
35
-			},
36
-			10,
37
-			4
38
-		);
39
-
40
-	}
41
-
42
-	private function save_field( $type, $identifier, $groups ) {
43
-
44
-		$entity_fields = $this->filter_entity_fields( $groups );
45
-
46
-		foreach ( $entity_fields as $entity_field ) {
47
-			delete_metadata( $type, $identifier, $entity_field );
48
-			$key = sprintf( 'pods_meta_%s', $entity_field );
49
-
50
-			$data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
51
-
52
-			if ( ! $data ) {
53
-				continue;
54
-			}
55
-			$values = $data[ $key ];
11
+    const FIELD_NAME = 'wlentity';
12
+
13
+    public function __construct() {
14
+
15
+        pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) );
16
+        add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 );
17
+        add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 );
18
+        add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 );
19
+        add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 );
20
+        add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 );
21
+
22
+        add_action(
23
+            'pods_meta_save_taxonomy',
24
+            function ( $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ) {
25
+                $this->save_field( 'term', $term_id, $groups );
26
+            },
27
+            10,
28
+            8
29
+        );
30
+
31
+        add_action(
32
+            'pods_meta_save_post',
33
+            function ( $data, $pod, $id, $groups ) {
34
+                $this->save_field( 'post', $id, $groups );
35
+            },
36
+            10,
37
+            4
38
+        );
39
+
40
+    }
41
+
42
+    private function save_field( $type, $identifier, $groups ) {
43
+
44
+        $entity_fields = $this->filter_entity_fields( $groups );
45
+
46
+        foreach ( $entity_fields as $entity_field ) {
47
+            delete_metadata( $type, $identifier, $entity_field );
48
+            $key = sprintf( 'pods_meta_%s', $entity_field );
49
+
50
+            $data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
51
+
52
+            if ( ! $data ) {
53
+                continue;
54
+            }
55
+            $values = $data[ $key ];
56 56
 
57
-			foreach ( $values as $value ) {
58
-				add_metadata( $type, $identifier, $entity_field, $value );
59
-			}
60
-		}
57
+            foreach ( $values as $value ) {
58
+                add_metadata( $type, $identifier, $entity_field, $value );
59
+            }
60
+        }
61 61
 
62
-	}
62
+    }
63 63
 
64
-	private function filter_entity_fields( $groups ) {
64
+    private function filter_entity_fields( $groups ) {
65 65
 
66
-		$pods = json_decode( wp_json_encode( $groups ), true );
67
-
68
-		$fields = array_reduce(
69
-			$pods,
70
-			function ( $carry, $item ) {
71
-				return array_merge( $carry, $item['fields'] );
72
-			},
73
-			array()
74
-		);
66
+        $pods = json_decode( wp_json_encode( $groups ), true );
67
+
68
+        $fields = array_reduce(
69
+            $pods,
70
+            function ( $carry, $item ) {
71
+                return array_merge( $carry, $item['fields'] );
72
+            },
73
+            array()
74
+        );
75 75
 
76
-		return array_map(
77
-			function ( $item ) {
78
-				return $item['name'];
79
-			},
80
-			array_filter(
81
-				$fields,
82
-				function ( $item ) {
83
-					return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object'];
84
-				}
85
-			)
86
-		);
87
-	}
76
+        return array_map(
77
+            function ( $item ) {
78
+                return $item['name'];
79
+            },
80
+            array_filter(
81
+                $fields,
82
+                function ( $item ) {
83
+                    return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object'];
84
+                }
85
+            )
86
+        );
87
+    }
88 88
 
89
-	public function wl_pods_transform_data_for_pick_field( $item ) {
90
-
91
-		$content = $item->get_content();
92
-
93
-		return array(
94
-			'id'        => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ),
95
-			'icon'      => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg',
96
-			'name'      => $item->get_title() . ' (' . $item->get_schema_type() . ')',
97
-			'edit_link' => $content->get_edit_link(),
98
-			'link'      => $content->get_permalink(),
99
-			'selected'  => false,
100
-		);
101
-	}
102
-
103
-
104
-	public function admin_ajax_filter( $data, $name, $_, $field ) {
105
-
106
-		if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) {
107
-			return $data;
108
-		}
109
-
110
-		$query         = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) );
111
-		$query_service = Entity_Query_Service::get_instance();
112
-
113
-		return array_map(
114
-			array(
115
-				$this,
116
-				'wl_pods_transform_data_for_pick_field',
117
-			),
118
-			$query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) )
119
-		);
120
-
121
-	}
122
-
123
-	public function data_filter( $data, $args ) {
124
-
125
-		$args_arr   = json_decode( wp_json_encode( $args ), true );
126
-		$field_data = $args_arr['options'];
89
+    public function wl_pods_transform_data_for_pick_field( $item ) {
90
+
91
+        $content = $item->get_content();
92
+
93
+        return array(
94
+            'id'        => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ),
95
+            'icon'      => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg',
96
+            'name'      => $item->get_title() . ' (' . $item->get_schema_type() . ')',
97
+            'edit_link' => $content->get_edit_link(),
98
+            'link'      => $content->get_permalink(),
99
+            'selected'  => false,
100
+        );
101
+    }
102
+
103
+
104
+    public function admin_ajax_filter( $data, $name, $_, $field ) {
105
+
106
+        if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) {
107
+            return $data;
108
+        }
109
+
110
+        $query         = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) );
111
+        $query_service = Entity_Query_Service::get_instance();
112
+
113
+        return array_map(
114
+            array(
115
+                $this,
116
+                'wl_pods_transform_data_for_pick_field',
117
+            ),
118
+            $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) )
119
+        );
120
+
121
+    }
122
+
123
+    public function data_filter( $data, $args ) {
124
+
125
+        $args_arr   = json_decode( wp_json_encode( $args ), true );
126
+        $field_data = $args_arr['options'];
127 127
 
128
-		if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) {
129
-			return $data;
130
-		}
128
+        if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) {
129
+            return $data;
130
+        }
131 131
 
132
-		if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] )
133
-			 || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) {
134
-			return $data;
135
-		}
132
+        if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] )
133
+             || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) {
134
+            return $data;
135
+        }
136 136
 
137
-		$name       = $field_data['name'];
138
-		$identifier = $args->id;
139
-		$type       = $args_arr['pod']['data']['pod_data']['type'];
137
+        $name       = $field_data['name'];
138
+        $identifier = $args->id;
139
+        $type       = $args_arr['pod']['data']['pod_data']['type'];
140 140
 
141
-		if ( 'post_type' === $type ) {
142
-			$data['fieldValue'] = get_post_meta( $identifier, $name );
143
-		} elseif ( 'taxonomy' === $type ) {
144
-			$data['fieldValue'] = get_term_meta( $identifier, $name );
145
-		}
141
+        if ( 'post_type' === $type ) {
142
+            $data['fieldValue'] = get_post_meta( $identifier, $name );
143
+        } elseif ( 'taxonomy' === $type ) {
144
+            $data['fieldValue'] = get_term_meta( $identifier, $name );
145
+        }
146 146
 
147
-		return $data;
148
-	}
147
+        return $data;
148
+    }
149 149
 
150 150
 
151
-	public function ajax_filter( $result, $name, $value, $field_options ) {
152
-
153
-		if ( ! isset( $field_options['pick_object'] ) ) {
154
-			return $result;
155
-		}
151
+    public function ajax_filter( $result, $name, $value, $field_options ) {
152
+
153
+        if ( ! isset( $field_options['pick_object'] ) ) {
154
+            return $result;
155
+        }
156 156
 
157
-		return self::FIELD_NAME === $field_options['pick_object'];
158
-	}
157
+        return self::FIELD_NAME === $field_options['pick_object'];
158
+    }
159 159
 
160
-	public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) {
160
+    public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) {
161 161
 
162
-		if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) {
163
-			return $info;
164
-		}
165
-		// We need to return an non empty array here to prevent pods from querying a table.
166
-		// This is necessary to prevent errors on ui.
167
-		return array( 'foo' => 'bar' );
168
-	}
169
-
170
-
171
-	public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) {
172
-
173
-		$object_params = json_decode( wp_json_encode( $object_params ), true );
162
+        if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) {
163
+            return $info;
164
+        }
165
+        // We need to return an non empty array here to prevent pods from querying a table.
166
+        // This is necessary to prevent errors on ui.
167
+        return array( 'foo' => 'bar' );
168
+    }
169
+
170
+
171
+    public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) {
172
+
173
+        $object_params = json_decode( wp_json_encode( $object_params ), true );
174 174
 
175
-		$query_service = Entity_Query_Service::get_instance();
176
-
177
-		if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] )
178
-			 && is_string( $object_params['options']['pick_object'] )
179
-			 && self::FIELD_NAME === $object_params['options']['pick_object']
180
-			 && isset( $object_params['pod']['data']['pod_data']['type'] )
181
-			 && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) {
175
+        $query_service = Entity_Query_Service::get_instance();
176
+
177
+        if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] )
178
+             && is_string( $object_params['options']['pick_object'] )
179
+             && self::FIELD_NAME === $object_params['options']['pick_object']
180
+             && isset( $object_params['pod']['data']['pod_data']['type'] )
181
+             && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) {
182 182
 
183
-			$type            = $object_params['pod']['data']['pod_data']['type'];
184
-			$linked_entities = array();
185
-			if ( 'post_type' === $type ) {
186
-				$linked_entities = get_post_meta( $id, $name );
187
-			} elseif ( 'taxonomy' === $type ) {
188
-				$linked_entities = get_term_meta( $id, $name );
189
-			}
190
-			$data            = array();
191
-			$linked_entities = $query_service->get( $linked_entities );
192
-			foreach ( $linked_entities as $linked_entity ) {
193
-				$content     = $linked_entity->get_content();
194
-				$id          = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() );
195
-				$text        = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')';
196
-				$data[ $id ] = $text;
197
-			}
183
+            $type            = $object_params['pod']['data']['pod_data']['type'];
184
+            $linked_entities = array();
185
+            if ( 'post_type' === $type ) {
186
+                $linked_entities = get_post_meta( $id, $name );
187
+            } elseif ( 'taxonomy' === $type ) {
188
+                $linked_entities = get_term_meta( $id, $name );
189
+            }
190
+            $data            = array();
191
+            $linked_entities = $query_service->get( $linked_entities );
192
+            foreach ( $linked_entities as $linked_entity ) {
193
+                $content     = $linked_entity->get_content();
194
+                $id          = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() );
195
+                $text        = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')';
196
+                $data[ $id ] = $text;
197
+            }
198 198
 
199
-			return $data;
200
-		}
199
+            return $data;
200
+        }
201 201
 
202
-		return $_;
202
+        return $_;
203 203
 
204
-	}
204
+    }
205 205
 
206 206
 
207 207
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -12,17 +12,17 @@  discard block
 block discarded – undo
12 12
 
13 13
 	public function __construct() {
14 14
 
15
-		pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) );
16
-		add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 );
17
-		add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 );
18
-		add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 );
19
-		add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 );
20
-		add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 );
15
+		pods_register_related_object(self::FIELD_NAME, 'WordLift Entity', array('simple' => false));
16
+		add_filter('pods_form_ui_field_pick_ajax', array($this, 'ajax_filter'), 10, 4);
17
+		add_filter('pods_api_get_table_info', array($this, 'table_info_filter'), 10, 6);
18
+		add_filter('pods_field_pick_object_data', array($this, 'field_options_filter'), 10, 7);
19
+		add_filter('pods_field_dfv_data', array($this, 'data_filter'), 10, 2);
20
+		add_filter('pods_field_pick_data_ajax', array($this, 'admin_ajax_filter'), 10, 4);
21 21
 
22 22
 		add_action(
23 23
 			'pods_meta_save_taxonomy',
24
-			function ( $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ) {
25
-				$this->save_field( 'term', $term_id, $groups );
24
+			function($data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item) {
25
+				$this->save_field('term', $term_id, $groups);
26 26
 			},
27 27
 			10,
28 28
 			8
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 
31 31
 		add_action(
32 32
 			'pods_meta_save_post',
33
-			function ( $data, $pod, $id, $groups ) {
34
-				$this->save_field( 'post', $id, $groups );
33
+			function($data, $pod, $id, $groups) {
34
+				$this->save_field('post', $id, $groups);
35 35
 			},
36 36
 			10,
37 37
 			4
@@ -39,61 +39,61 @@  discard block
 block discarded – undo
39 39
 
40 40
 	}
41 41
 
42
-	private function save_field( $type, $identifier, $groups ) {
42
+	private function save_field($type, $identifier, $groups) {
43 43
 
44
-		$entity_fields = $this->filter_entity_fields( $groups );
44
+		$entity_fields = $this->filter_entity_fields($groups);
45 45
 
46
-		foreach ( $entity_fields as $entity_field ) {
47
-			delete_metadata( $type, $identifier, $entity_field );
48
-			$key = sprintf( 'pods_meta_%s', $entity_field );
46
+		foreach ($entity_fields as $entity_field) {
47
+			delete_metadata($type, $identifier, $entity_field);
48
+			$key = sprintf('pods_meta_%s', $entity_field);
49 49
 
50
-			$data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
50
+			$data = filter_var_array($_REQUEST, array($key => array('flags' => FILTER_REQUIRE_ARRAY))); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
51 51
 
52
-			if ( ! $data ) {
52
+			if ( ! $data) {
53 53
 				continue;
54 54
 			}
55
-			$values = $data[ $key ];
55
+			$values = $data[$key];
56 56
 
57
-			foreach ( $values as $value ) {
58
-				add_metadata( $type, $identifier, $entity_field, $value );
57
+			foreach ($values as $value) {
58
+				add_metadata($type, $identifier, $entity_field, $value);
59 59
 			}
60 60
 		}
61 61
 
62 62
 	}
63 63
 
64
-	private function filter_entity_fields( $groups ) {
64
+	private function filter_entity_fields($groups) {
65 65
 
66
-		$pods = json_decode( wp_json_encode( $groups ), true );
66
+		$pods = json_decode(wp_json_encode($groups), true);
67 67
 
68 68
 		$fields = array_reduce(
69 69
 			$pods,
70
-			function ( $carry, $item ) {
71
-				return array_merge( $carry, $item['fields'] );
70
+			function($carry, $item) {
71
+				return array_merge($carry, $item['fields']);
72 72
 			},
73 73
 			array()
74 74
 		);
75 75
 
76 76
 		return array_map(
77
-			function ( $item ) {
77
+			function($item) {
78 78
 				return $item['name'];
79 79
 			},
80 80
 			array_filter(
81 81
 				$fields,
82
-				function ( $item ) {
83
-					return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object'];
82
+				function($item) {
83
+					return is_array($item) && isset($item['pick_object']) && self::FIELD_NAME === $item['pick_object'];
84 84
 				}
85 85
 			)
86 86
 		);
87 87
 	}
88 88
 
89
-	public function wl_pods_transform_data_for_pick_field( $item ) {
89
+	public function wl_pods_transform_data_for_pick_field($item) {
90 90
 
91 91
 		$content = $item->get_content();
92 92
 
93 93
 		return array(
94
-			'id'        => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ),
94
+			'id'        => sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id()),
95 95
 			'icon'      => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg',
96
-			'name'      => $item->get_title() . ' (' . $item->get_schema_type() . ')',
96
+			'name'      => $item->get_title().' ('.$item->get_schema_type().')',
97 97
 			'edit_link' => $content->get_edit_link(),
98 98
 			'link'      => $content->get_permalink(),
99 99
 			'selected'  => false,
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 	}
102 102
 
103 103
 
104
-	public function admin_ajax_filter( $data, $name, $_, $field ) {
104
+	public function admin_ajax_filter($data, $name, $_, $field) {
105 105
 
106
-		if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) {
106
+		if (( ! $field instanceof \Pods\Whatsit\Field) || $field->get_arg('pick_object', false) !== self::FIELD_NAME) {
107 107
 			return $data;
108 108
 		}
109 109
 
110
-		$query         = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) );
110
+		$query         = sanitize_text_field(wp_unslash($_REQUEST['query']));
111 111
 		$query_service = Entity_Query_Service::get_instance();
112 112
 
113 113
 		return array_map(
@@ -115,22 +115,22 @@  discard block
 block discarded – undo
115 115
 				$this,
116 116
 				'wl_pods_transform_data_for_pick_field',
117 117
 			),
118
-			$query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) )
118
+			$query_service->query($query, $field->get_arg('supported_schema_types', array('Thing')))
119 119
 		);
120 120
 
121 121
 	}
122 122
 
123
-	public function data_filter( $data, $args ) {
123
+	public function data_filter($data, $args) {
124 124
 
125
-		$args_arr   = json_decode( wp_json_encode( $args ), true );
125
+		$args_arr   = json_decode(wp_json_encode($args), true);
126 126
 		$field_data = $args_arr['options'];
127 127
 
128
-		if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) {
128
+		if ( ! isset($field_data['pick_object']) || self::FIELD_NAME !== $field_data['pick_object']) {
129 129
 			return $data;
130 130
 		}
131 131
 
132
-		if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] )
133
-			 || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) {
132
+		if ( ! isset($args_arr['pod']['data']['pod_data']['type'])
133
+			 || ! is_string($args_arr['pod']['data']['pod_data']['type'])) {
134 134
 			return $data;
135 135
 		}
136 136
 
@@ -138,62 +138,62 @@  discard block
 block discarded – undo
138 138
 		$identifier = $args->id;
139 139
 		$type       = $args_arr['pod']['data']['pod_data']['type'];
140 140
 
141
-		if ( 'post_type' === $type ) {
142
-			$data['fieldValue'] = get_post_meta( $identifier, $name );
143
-		} elseif ( 'taxonomy' === $type ) {
144
-			$data['fieldValue'] = get_term_meta( $identifier, $name );
141
+		if ('post_type' === $type) {
142
+			$data['fieldValue'] = get_post_meta($identifier, $name);
143
+		} elseif ('taxonomy' === $type) {
144
+			$data['fieldValue'] = get_term_meta($identifier, $name);
145 145
 		}
146 146
 
147 147
 		return $data;
148 148
 	}
149 149
 
150 150
 
151
-	public function ajax_filter( $result, $name, $value, $field_options ) {
151
+	public function ajax_filter($result, $name, $value, $field_options) {
152 152
 
153
-		if ( ! isset( $field_options['pick_object'] ) ) {
153
+		if ( ! isset($field_options['pick_object'])) {
154 154
 			return $result;
155 155
 		}
156 156
 
157 157
 		return self::FIELD_NAME === $field_options['pick_object'];
158 158
 	}
159 159
 
160
-	public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) {
160
+	public function table_info_filter($info, $object_type, $object, $name, $pod, $field) {
161 161
 
162
-		if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) {
162
+		if ($field === null || self::FIELD_NAME !== $field->get_arg('pick_object', false)) {
163 163
 			return $info;
164 164
 		}
165 165
 		// We need to return an non empty array here to prevent pods from querying a table.
166 166
 		// This is necessary to prevent errors on ui.
167
-		return array( 'foo' => 'bar' );
167
+		return array('foo' => 'bar');
168 168
 	}
169 169
 
170 170
 
171
-	public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) {
171
+	public function field_options_filter($_, $name, $value, $options, $pod, $id, $object_params) {
172 172
 
173
-		$object_params = json_decode( wp_json_encode( $object_params ), true );
173
+		$object_params = json_decode(wp_json_encode($object_params), true);
174 174
 
175 175
 		$query_service = Entity_Query_Service::get_instance();
176 176
 
177
-		if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] )
178
-			 && is_string( $object_params['options']['pick_object'] )
177
+		if (is_array($object_params) && isset($object_params['options']['pick_object'])
178
+			 && is_string($object_params['options']['pick_object'])
179 179
 			 && self::FIELD_NAME === $object_params['options']['pick_object']
180
-			 && isset( $object_params['pod']['data']['pod_data']['type'] )
181
-			 && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) {
180
+			 && isset($object_params['pod']['data']['pod_data']['type'])
181
+			 && is_string($object_params['pod']['data']['pod_data']['type'])) {
182 182
 
183 183
 			$type            = $object_params['pod']['data']['pod_data']['type'];
184 184
 			$linked_entities = array();
185
-			if ( 'post_type' === $type ) {
186
-				$linked_entities = get_post_meta( $id, $name );
187
-			} elseif ( 'taxonomy' === $type ) {
188
-				$linked_entities = get_term_meta( $id, $name );
185
+			if ('post_type' === $type) {
186
+				$linked_entities = get_post_meta($id, $name);
187
+			} elseif ('taxonomy' === $type) {
188
+				$linked_entities = get_term_meta($id, $name);
189 189
 			}
190 190
 			$data            = array();
191
-			$linked_entities = $query_service->get( $linked_entities );
192
-			foreach ( $linked_entities as $linked_entity ) {
191
+			$linked_entities = $query_service->get($linked_entities);
192
+			foreach ($linked_entities as $linked_entity) {
193 193
 				$content     = $linked_entity->get_content();
194
-				$id          = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() );
195
-				$text        = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')';
196
-				$data[ $id ] = $text;
194
+				$id          = sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id());
195
+				$text        = $linked_entity->get_title().' ('.$linked_entity->get_schema_type().')';
196
+				$data[$id] = $text;
197 197
 			}
198 198
 
199 199
 			return $data;
Please login to merge, or discard this patch.