Completed
Pull Request — develop (#1576)
by Naveen
01:35
created
src/modules/pods/includes/WlEntityField/Filters.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -7,129 +7,129 @@
 block discarded – undo
7 7
 
8 8
 class Filters {
9 9
 
10
-	const FIELD_NAME = 'wlentity';
10
+    const FIELD_NAME = 'wlentity';
11 11
 
12
-	public function __construct() {
12
+    public function __construct() {
13 13
 
14
-		pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) );
15
-		add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 );
16
-		add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 );
17
-		add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 );
18
-		add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 );
19
-		add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 );
14
+        pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) );
15
+        add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 );
16
+        add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 );
17
+        add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 );
18
+        add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 );
19
+        add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 );
20 20
 
21
-	}
21
+    }
22 22
 
23
-	public function wl_pods_transform_data_for_pick_field( $item ) {
23
+    public function wl_pods_transform_data_for_pick_field( $item ) {
24 24
 
25
-		$content = $item->get_content();
25
+        $content = $item->get_content();
26 26
 
27
-		return array(
28
-			'id'        => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ),
29
-			'icon'      => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg',
30
-			'name'      => $item->get_title() . ' (' . $item->get_schema_type() . ')',
31
-			'edit_link' => $content->get_edit_link(),
32
-			'link'      => $content->get_permalink(),
33
-			'selected'  => false,
34
-		);
35
-	}
27
+        return array(
28
+            'id'        => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ),
29
+            'icon'      => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg',
30
+            'name'      => $item->get_title() . ' (' . $item->get_schema_type() . ')',
31
+            'edit_link' => $content->get_edit_link(),
32
+            'link'      => $content->get_permalink(),
33
+            'selected'  => false,
34
+        );
35
+    }
36 36
 
37 37
 
38
-	public function admin_ajax_filter( $data, $name, $_, $field ) {
38
+    public function admin_ajax_filter( $data, $name, $_, $field ) {
39 39
 
40
-		if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) {
41
-			return $data;
42
-		}
40
+        if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) {
41
+            return $data;
42
+        }
43 43
 
44
-		$query         = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) );
45
-		$query_service = Entity_Query_Service::get_instance();
44
+        $query         = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) );
45
+        $query_service = Entity_Query_Service::get_instance();
46 46
 
47
-		return array_map( array( $this, 'wl_pods_transform_data_for_pick_field' ), $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) );
47
+        return array_map( array( $this, 'wl_pods_transform_data_for_pick_field' ), $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) );
48 48
 
49
-	}
49
+    }
50 50
 
51
-	public function data_filter( $data, $args ) {
51
+    public function data_filter( $data, $args ) {
52 52
 
53
-		$args_arr   = json_decode( wp_json_encode( $args ), true );
54
-		$field_data = $args_arr['options'];
53
+        $args_arr   = json_decode( wp_json_encode( $args ), true );
54
+        $field_data = $args_arr['options'];
55 55
 
56
-		if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) {
57
-			return $data;
58
-		}
56
+        if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) {
57
+            return $data;
58
+        }
59 59
 
60
-		if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] )
61
-			 || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) {
62
-			return $data;
63
-		}
60
+        if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] )
61
+             || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) {
62
+            return $data;
63
+        }
64 64
 
65
-		$name       = $field_data['name'];
66
-		$identifier = $args->id;
67
-		$type       = $args_arr['pod']['data']['pod_data']['type'];
65
+        $name       = $field_data['name'];
66
+        $identifier = $args->id;
67
+        $type       = $args_arr['pod']['data']['pod_data']['type'];
68 68
 
69
-		if ( 'post_type' === $type ) {
70
-			$data['fieldValue'] = get_post_meta( $identifier, $name );
71
-		} elseif ( 'taxonomy' === $type ) {
72
-			$data['fieldValue'] = get_term_meta( $identifier, $name );
73
-		}
69
+        if ( 'post_type' === $type ) {
70
+            $data['fieldValue'] = get_post_meta( $identifier, $name );
71
+        } elseif ( 'taxonomy' === $type ) {
72
+            $data['fieldValue'] = get_term_meta( $identifier, $name );
73
+        }
74 74
 
75
-		return $data;
76
-	}
75
+        return $data;
76
+    }
77 77
 
78 78
 
79
-	public function ajax_filter( $result, $name, $value, $field_options ) {
79
+    public function ajax_filter( $result, $name, $value, $field_options ) {
80 80
 
81
-		if ( ! isset( $field_options['pick_object'] ) ) {
82
-			return $result;
83
-		}
81
+        if ( ! isset( $field_options['pick_object'] ) ) {
82
+            return $result;
83
+        }
84 84
 
85
-		return self::FIELD_NAME === $field_options['pick_object'];
86
-	}
85
+        return self::FIELD_NAME === $field_options['pick_object'];
86
+    }
87 87
 
88
-	public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) {
88
+    public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) {
89 89
 
90
-		if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) {
91
-			return $info;
92
-		}
93
-		// We need to return an non empty array here to prevent pods from querying a table.
94
-		// This is necessary to prevent errors on ui.
95
-		return array( 'foo' => 'bar' );
96
-	}
90
+        if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) {
91
+            return $info;
92
+        }
93
+        // We need to return an non empty array here to prevent pods from querying a table.
94
+        // This is necessary to prevent errors on ui.
95
+        return array( 'foo' => 'bar' );
96
+    }
97 97
 
98 98
 
99
-	public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) {
99
+    public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) {
100 100
 
101
-		$object_params = json_decode( wp_json_encode( $object_params ), true );
101
+        $object_params = json_decode( wp_json_encode( $object_params ), true );
102 102
 
103
-		$query_service = Entity_Query_Service::get_instance();
103
+        $query_service = Entity_Query_Service::get_instance();
104 104
 
105
-		if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] )
106
-			 && is_string( $object_params['options']['pick_object'] )
107
-			 && self::FIELD_NAME === $object_params['options']['pick_object']
108
-			 && isset( $object_params['pod']['data']['pod_data']['type'] )
109
-			 && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) {
105
+        if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] )
106
+             && is_string( $object_params['options']['pick_object'] )
107
+             && self::FIELD_NAME === $object_params['options']['pick_object']
108
+             && isset( $object_params['pod']['data']['pod_data']['type'] )
109
+             && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) {
110 110
 
111
-			$type            = $object_params['pod']['data']['pod_data']['type'];
112
-			$linked_entities = array();
113
-			if ( 'post_type' === $type ) {
114
-				$linked_entities = get_post_meta( $id, $name );
115
-			} elseif ( 'taxonomy' === $type ) {
116
-				$linked_entities = get_term_meta( $id, $name );
117
-			}
118
-			$data            = array();
119
-			$linked_entities = $query_service->get( $linked_entities );
120
-			foreach ( $linked_entities as $linked_entity ) {
121
-				$content     = $linked_entity->get_content();
122
-				$id          = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() );
123
-				$text        = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')';
124
-				$data[ $id ] = $text;
125
-			}
111
+            $type            = $object_params['pod']['data']['pod_data']['type'];
112
+            $linked_entities = array();
113
+            if ( 'post_type' === $type ) {
114
+                $linked_entities = get_post_meta( $id, $name );
115
+            } elseif ( 'taxonomy' === $type ) {
116
+                $linked_entities = get_term_meta( $id, $name );
117
+            }
118
+            $data            = array();
119
+            $linked_entities = $query_service->get( $linked_entities );
120
+            foreach ( $linked_entities as $linked_entity ) {
121
+                $content     = $linked_entity->get_content();
122
+                $id          = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() );
123
+                $text        = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')';
124
+                $data[ $id ] = $text;
125
+            }
126 126
 
127
-			return $data;
128
-		}
127
+            return $data;
128
+        }
129 129
 
130
-		return $_;
130
+        return $_;
131 131
 
132
-	}
132
+    }
133 133
 
134 134
 
135 135
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -11,23 +11,23 @@  discard block
 block discarded – undo
11 11
 
12 12
 	public function __construct() {
13 13
 
14
-		pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) );
15
-		add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 );
16
-		add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 );
17
-		add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 );
18
-		add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 );
19
-		add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 );
14
+		pods_register_related_object(self::FIELD_NAME, 'WordLift Entity', array('simple' => false));
15
+		add_filter('pods_form_ui_field_pick_ajax', array($this, 'ajax_filter'), 10, 4);
16
+		add_filter('pods_api_get_table_info', array($this, 'table_info_filter'), 10, 6);
17
+		add_filter('pods_field_pick_object_data', array($this, 'field_options_filter'), 10, 7);
18
+		add_filter('pods_field_dfv_data', array($this, 'data_filter'), 10, 2);
19
+		add_filter('pods_field_pick_data_ajax', array($this, 'admin_ajax_filter'), 10, 4);
20 20
 
21 21
 	}
22 22
 
23
-	public function wl_pods_transform_data_for_pick_field( $item ) {
23
+	public function wl_pods_transform_data_for_pick_field($item) {
24 24
 
25 25
 		$content = $item->get_content();
26 26
 
27 27
 		return array(
28
-			'id'        => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ),
28
+			'id'        => sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id()),
29 29
 			'icon'      => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg',
30
-			'name'      => $item->get_title() . ' (' . $item->get_schema_type() . ')',
30
+			'name'      => $item->get_title().' ('.$item->get_schema_type().')',
31 31
 			'edit_link' => $content->get_edit_link(),
32 32
 			'link'      => $content->get_permalink(),
33 33
 			'selected'  => false,
@@ -35,30 +35,30 @@  discard block
 block discarded – undo
35 35
 	}
36 36
 
37 37
 
38
-	public function admin_ajax_filter( $data, $name, $_, $field ) {
38
+	public function admin_ajax_filter($data, $name, $_, $field) {
39 39
 
40
-		if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) {
40
+		if (( ! $field instanceof \Pods\Whatsit\Field) || $field->get_arg('pick_object', false) !== self::FIELD_NAME) {
41 41
 			return $data;
42 42
 		}
43 43
 
44
-		$query         = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) );
44
+		$query         = sanitize_text_field(wp_unslash($_REQUEST['query']));
45 45
 		$query_service = Entity_Query_Service::get_instance();
46 46
 
47
-		return array_map( array( $this, 'wl_pods_transform_data_for_pick_field' ), $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) );
47
+		return array_map(array($this, 'wl_pods_transform_data_for_pick_field'), $query_service->query($query, $field->get_arg('supported_schema_types', array('Thing'))));
48 48
 
49 49
 	}
50 50
 
51
-	public function data_filter( $data, $args ) {
51
+	public function data_filter($data, $args) {
52 52
 
53
-		$args_arr   = json_decode( wp_json_encode( $args ), true );
53
+		$args_arr   = json_decode(wp_json_encode($args), true);
54 54
 		$field_data = $args_arr['options'];
55 55
 
56
-		if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) {
56
+		if ( ! isset($field_data['pick_object']) || self::FIELD_NAME !== $field_data['pick_object']) {
57 57
 			return $data;
58 58
 		}
59 59
 
60
-		if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] )
61
-			 || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) {
60
+		if ( ! isset($args_arr['pod']['data']['pod_data']['type'])
61
+			 || ! is_string($args_arr['pod']['data']['pod_data']['type'])) {
62 62
 			return $data;
63 63
 		}
64 64
 
@@ -66,62 +66,62 @@  discard block
 block discarded – undo
66 66
 		$identifier = $args->id;
67 67
 		$type       = $args_arr['pod']['data']['pod_data']['type'];
68 68
 
69
-		if ( 'post_type' === $type ) {
70
-			$data['fieldValue'] = get_post_meta( $identifier, $name );
71
-		} elseif ( 'taxonomy' === $type ) {
72
-			$data['fieldValue'] = get_term_meta( $identifier, $name );
69
+		if ('post_type' === $type) {
70
+			$data['fieldValue'] = get_post_meta($identifier, $name);
71
+		} elseif ('taxonomy' === $type) {
72
+			$data['fieldValue'] = get_term_meta($identifier, $name);
73 73
 		}
74 74
 
75 75
 		return $data;
76 76
 	}
77 77
 
78 78
 
79
-	public function ajax_filter( $result, $name, $value, $field_options ) {
79
+	public function ajax_filter($result, $name, $value, $field_options) {
80 80
 
81
-		if ( ! isset( $field_options['pick_object'] ) ) {
81
+		if ( ! isset($field_options['pick_object'])) {
82 82
 			return $result;
83 83
 		}
84 84
 
85 85
 		return self::FIELD_NAME === $field_options['pick_object'];
86 86
 	}
87 87
 
88
-	public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) {
88
+	public function table_info_filter($info, $object_type, $object, $name, $pod, $field) {
89 89
 
90
-		if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) {
90
+		if ($field === null || self::FIELD_NAME !== $field->get_arg('pick_object', false)) {
91 91
 			return $info;
92 92
 		}
93 93
 		// We need to return an non empty array here to prevent pods from querying a table.
94 94
 		// This is necessary to prevent errors on ui.
95
-		return array( 'foo' => 'bar' );
95
+		return array('foo' => 'bar');
96 96
 	}
97 97
 
98 98
 
99
-	public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) {
99
+	public function field_options_filter($_, $name, $value, $options, $pod, $id, $object_params) {
100 100
 
101
-		$object_params = json_decode( wp_json_encode( $object_params ), true );
101
+		$object_params = json_decode(wp_json_encode($object_params), true);
102 102
 
103 103
 		$query_service = Entity_Query_Service::get_instance();
104 104
 
105
-		if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] )
106
-			 && is_string( $object_params['options']['pick_object'] )
105
+		if (is_array($object_params) && isset($object_params['options']['pick_object'])
106
+			 && is_string($object_params['options']['pick_object'])
107 107
 			 && self::FIELD_NAME === $object_params['options']['pick_object']
108
-			 && isset( $object_params['pod']['data']['pod_data']['type'] )
109
-			 && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) {
108
+			 && isset($object_params['pod']['data']['pod_data']['type'])
109
+			 && is_string($object_params['pod']['data']['pod_data']['type'])) {
110 110
 
111 111
 			$type            = $object_params['pod']['data']['pod_data']['type'];
112 112
 			$linked_entities = array();
113
-			if ( 'post_type' === $type ) {
114
-				$linked_entities = get_post_meta( $id, $name );
115
-			} elseif ( 'taxonomy' === $type ) {
116
-				$linked_entities = get_term_meta( $id, $name );
113
+			if ('post_type' === $type) {
114
+				$linked_entities = get_post_meta($id, $name);
115
+			} elseif ('taxonomy' === $type) {
116
+				$linked_entities = get_term_meta($id, $name);
117 117
 			}
118 118
 			$data            = array();
119
-			$linked_entities = $query_service->get( $linked_entities );
120
-			foreach ( $linked_entities as $linked_entity ) {
119
+			$linked_entities = $query_service->get($linked_entities);
120
+			foreach ($linked_entities as $linked_entity) {
121 121
 				$content     = $linked_entity->get_content();
122
-				$id          = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() );
123
-				$text        = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')';
124
-				$data[ $id ] = $text;
122
+				$id          = sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id());
123
+				$text        = $linked_entity->get_title().' ('.$linked_entity->get_schema_type().')';
124
+				$data[$id] = $text;
125 125
 			}
126 126
 
127 127
 			return $data;
Please login to merge, or discard this patch.