From ef40f99ce1908813b408e2675d2ec2db36d9766d Mon Sep 17 00:00:00 2001 From: NiclasNorin Date: Mon, 15 Sep 2025 14:13:54 +0200 Subject: [PATCH 1/3] refactor: acfe field to normal checkbox --- .../json/mod-posts-taxonomydisplay.json | 39 ++++++++++++------ .../php/mod-posts-taxonomydisplay.php | 40 ++++++++++++------- source/php/Module/Posts/Posts.php | 28 ++++++++++++- 3 files changed, 79 insertions(+), 28 deletions(-) diff --git a/source/php/AcfFields/json/mod-posts-taxonomydisplay.json b/source/php/AcfFields/json/mod-posts-taxonomydisplay.json index 2c8e1e0db..451a947ed 100644 --- a/source/php/AcfFields/json/mod-posts-taxonomydisplay.json +++ b/source/php/AcfFields/json/mod-posts-taxonomydisplay.json @@ -7,7 +7,7 @@ "label": "Taxonomies to display", "name": "taxonomy_display", "aria-label": "", - "type": "acfe_taxonomies", + "type": "checkbox", "instructions": "", "required": 0, "conditional_logic": 0, @@ -16,21 +16,34 @@ "class": "", "id": "" }, - "taxonomy": "", - "field_type": "checkbox", + "choices": { + "category": "Category", + "post_tag": "Tag", + "nav_menu": "Navigation Menu", + "link_category": "Link Category", + "post_format": "Format", + "wp_theme": "Theme", + "wp_template_part_area": "Template Part Area", + "wp_pattern_category": "Pattern Category", + "event_categories": "Event category", + "event_tags": "Event tag", + "event_groups": "Event group", + "user_group": "User Groups", + "acf-field-group-category": "Categories", + "feedback_topic": "Topic", + "test": "Test", + "custom": "Custom", + "job_posting_relevant_occupation": "Job Category", + "job_posting_valid_through": "Latest Application Date" + }, "default_value": [], - "return_format": "name", + "return_format": "value", + "allow_custom": 0, + "allow_in_bindings": 0, "layout": "horizontal", "toggle": 0, - "allow_custom": 0, - "multiple": 0, - "allow_null": 0, - "choices": [], - "ui": 0, - "ajax": 0, - "placeholder": "", - "search_placeholder": "", - "other_choice": 0 + "save_custom": 0, + "custom_choice_button_text": "Add new choice" } ], "location": [ diff --git a/source/php/AcfFields/php/mod-posts-taxonomydisplay.php b/source/php/AcfFields/php/mod-posts-taxonomydisplay.php index d288c5119..1d96a7577 100644 --- a/source/php/AcfFields/php/mod-posts-taxonomydisplay.php +++ b/source/php/AcfFields/php/mod-posts-taxonomydisplay.php @@ -10,7 +10,7 @@ 'label' => __('Taxonomies to display', 'modularity'), 'name' => 'taxonomy_display', 'aria-label' => '', - 'type' => 'acfe_taxonomies', + 'type' => 'checkbox', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, @@ -19,23 +19,35 @@ 'class' => '', 'id' => '', ), - 'taxonomy' => '', - 'field_type' => 'checkbox', + 'choices' => array( + 'category' => __('Category', 'modularity'), + 'post_tag' => __('Tag', 'modularity'), + 'nav_menu' => __('Navigation Menu', 'modularity'), + 'link_category' => __('Link Category', 'modularity'), + 'post_format' => __('Format', 'modularity'), + 'wp_theme' => __('Theme', 'modularity'), + 'wp_template_part_area' => __('Template Part Area', 'modularity'), + 'wp_pattern_category' => __('Pattern Category', 'modularity'), + 'event_categories' => __('Event category', 'modularity'), + 'event_tags' => __('Event tag', 'modularity'), + 'event_groups' => __('Event group', 'modularity'), + 'user_group' => __('User Groups', 'modularity'), + 'acf-field-group-category' => __('Categories', 'modularity'), + 'feedback_topic' => __('Topic', 'modularity'), + 'test' => __('Test', 'modularity'), + 'custom' => __('Custom', 'modularity'), + 'job_posting_relevant_occupation' => __('Job Category', 'modularity'), + 'job_posting_valid_through' => __('Latest Application Date', 'modularity'), + ), 'default_value' => array( ), - 'return_format' => 'name', + 'return_format' => 'value', + 'allow_custom' => 0, + 'allow_in_bindings' => 0, 'layout' => 'horizontal', 'toggle' => 0, - 'allow_custom' => 0, - 'multiple' => 0, - 'allow_null' => 0, - 'choices' => array( - ), - 'ui' => 0, - 'ajax' => 0, - 'placeholder' => '', - 'search_placeholder' => '', - 'other_choice' => 0, + 'save_custom' => 0, + 'custom_choice_button_text' => 'Add new choice', ), ), 'location' => array( diff --git a/source/php/Module/Posts/Posts.php b/source/php/Module/Posts/Posts.php index 5074bbf9b..3b9c88c23 100644 --- a/source/php/Module/Posts/Posts.php +++ b/source/php/Module/Posts/Posts.php @@ -60,6 +60,11 @@ public function init() 'acf/fields/post_object/query/name=posts_data_posts', array($this, 'removeUnwantedPostTypesFromManuallyPicked'), 10, 3 ); + + add_filter( + 'acf/load_field/name=taxonomy_display', + array($this, 'loadTaxonomyDisplayField') + ); // Helpers $this->archiveUrlHelper = new GetArchiveUrl(); @@ -85,7 +90,28 @@ public function loadSchemaTypesField(array $field = []):array { return $field; } - public function loadNetworkSourcesField(array $field = []):array { + /** + * Load taxonomy display field + * + * @param array $field + * @return array + */ + public function loadTaxonomyDisplayField(array $field = []): array + { + $taxonomies = get_taxonomies([], 'objects'); + + $choices = []; + foreach ($taxonomies as $taxonomyName => $taxonomyObj) { + $choices[$taxonomyName] = $taxonomyObj->labels->singular_name; + } + + $field['choices'] = $choices; + + return $field; + } + + public function loadNetworkSourcesField(array $field = []) :array + { if(!is_multisite() || get_post_type() === 'acf-field-group') { return $field; From 9d6eacb97566b401b9d14e2d2d15e489ae1e4912 Mon Sep 17 00:00:00 2001 From: NiclasNorin Date: Mon, 15 Sep 2025 14:25:08 +0200 Subject: [PATCH 2/3] fix: only public taxonomies --- source/php/Module/Posts/Posts.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/php/Module/Posts/Posts.php b/source/php/Module/Posts/Posts.php index 3b9c88c23..5eac375d9 100644 --- a/source/php/Module/Posts/Posts.php +++ b/source/php/Module/Posts/Posts.php @@ -98,7 +98,9 @@ public function loadSchemaTypesField(array $field = []):array { */ public function loadTaxonomyDisplayField(array $field = []): array { - $taxonomies = get_taxonomies([], 'objects'); + $taxonomies = get_taxonomies([ + 'public' => true + ], 'objects'); $choices = []; foreach ($taxonomies as $taxonomyName => $taxonomyObj) { From 085634462bf28125eb962f3de11b14fdf121200e Mon Sep 17 00:00:00 2001 From: NiclasNorin Date: Thu, 18 Sep 2025 09:13:48 +0200 Subject: [PATCH 3/3] fix: removing choices --- .../json/mod-posts-taxonomydisplay.json | 23 ++----------- .../php/mod-posts-taxonomydisplay.php | 32 +++++-------------- 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/source/php/AcfFields/json/mod-posts-taxonomydisplay.json b/source/php/AcfFields/json/mod-posts-taxonomydisplay.json index 451a947ed..408f44c7e 100644 --- a/source/php/AcfFields/json/mod-posts-taxonomydisplay.json +++ b/source/php/AcfFields/json/mod-posts-taxonomydisplay.json @@ -16,26 +16,7 @@ "class": "", "id": "" }, - "choices": { - "category": "Category", - "post_tag": "Tag", - "nav_menu": "Navigation Menu", - "link_category": "Link Category", - "post_format": "Format", - "wp_theme": "Theme", - "wp_template_part_area": "Template Part Area", - "wp_pattern_category": "Pattern Category", - "event_categories": "Event category", - "event_tags": "Event tag", - "event_groups": "Event group", - "user_group": "User Groups", - "acf-field-group-category": "Categories", - "feedback_topic": "Topic", - "test": "Test", - "custom": "Custom", - "job_posting_relevant_occupation": "Job Category", - "job_posting_valid_through": "Latest Application Date" - }, + "choices": {}, "default_value": [], "return_format": "value", "allow_custom": 0, @@ -77,4 +58,4 @@ "acfe_meta": "", "acfe_note": "" }] - \ No newline at end of file + diff --git a/source/php/AcfFields/php/mod-posts-taxonomydisplay.php b/source/php/AcfFields/php/mod-posts-taxonomydisplay.php index 1d96a7577..ed7eb0977 100644 --- a/source/php/AcfFields/php/mod-posts-taxonomydisplay.php +++ b/source/php/AcfFields/php/mod-posts-taxonomydisplay.php @@ -1,7 +1,9 @@ 'group_630645d822841', 'title' => __('Taxonomies to display', 'modularity'), 'fields' => array( @@ -19,26 +21,7 @@ 'class' => '', 'id' => '', ), - 'choices' => array( - 'category' => __('Category', 'modularity'), - 'post_tag' => __('Tag', 'modularity'), - 'nav_menu' => __('Navigation Menu', 'modularity'), - 'link_category' => __('Link Category', 'modularity'), - 'post_format' => __('Format', 'modularity'), - 'wp_theme' => __('Theme', 'modularity'), - 'wp_template_part_area' => __('Template Part Area', 'modularity'), - 'wp_pattern_category' => __('Pattern Category', 'modularity'), - 'event_categories' => __('Event category', 'modularity'), - 'event_tags' => __('Event tag', 'modularity'), - 'event_groups' => __('Event group', 'modularity'), - 'user_group' => __('User Groups', 'modularity'), - 'acf-field-group-category' => __('Categories', 'modularity'), - 'feedback_topic' => __('Topic', 'modularity'), - 'test' => __('Test', 'modularity'), - 'custom' => __('Custom', 'modularity'), - 'job_posting_relevant_occupation' => __('Job Category', 'modularity'), - 'job_posting_valid_through' => __('Latest Application Date', 'modularity'), - ), + 'choices' => array(), 'default_value' => array( ), 'return_format' => 'value', @@ -81,4 +64,5 @@ 'acfe_meta' => '', 'acfe_note' => '', )); - } \ No newline at end of file + +} \ No newline at end of file