@@ -4,101 +4,101 @@ |
||
| 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 | } |
@@ -8,200 +8,200 @@ |
||
| 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 | } |