From 81943b50043cd9ac84381423d07788fa3a8c684b Mon Sep 17 00:00:00 2001 From: Oleksandr Zhyian Date: Wed, 18 Dec 2024 09:04:50 +0200 Subject: [PATCH] feat: introduce editableOnly method for admin-only taxonomy visibility and editing --- src/Infrastructure/Content/Taxonomy/Taxonomy.php | 14 ++++++++++++++ tests/unit/Content/TaxonomyTest.php | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Infrastructure/Content/Taxonomy/Taxonomy.php b/src/Infrastructure/Content/Taxonomy/Taxonomy.php index f92502e..589ef9c 100644 --- a/src/Infrastructure/Content/Taxonomy/Taxonomy.php +++ b/src/Infrastructure/Content/Taxonomy/Taxonomy.php @@ -48,6 +48,20 @@ final public static function hidden(): static ); } + final public static function editableOnly(): static + { + return self::default()->merge( + [ + 'public' => false, + 'show_ui' => true, + 'show_in_menu' => true, + 'show_in_nav_menus' => false, + 'show_in_rest' => true, + 'meta_box_cb' => false, + ] + ); + } + final public function args(): array { return $this->args; diff --git a/tests/unit/Content/TaxonomyTest.php b/tests/unit/Content/TaxonomyTest.php index 5563fb4..36beb4b 100644 --- a/tests/unit/Content/TaxonomyTest.php +++ b/tests/unit/Content/TaxonomyTest.php @@ -50,6 +50,22 @@ public function testTaxonomyArgGeneration(): void DegreeTaxonomy::public()->args() ); + $this->assertSame( + [ + 'label' => 'Degrees', + 'labels' => $expectedLabels, + 'hierarchical' => true, + 'rest_base' => 'degree', + 'public' => false, + 'show_ui' => true, + 'show_in_menu' => true, + 'show_in_nav_menus' => false, + 'show_in_rest' => true, + 'meta_box_cb' => false, + ], + DegreeTaxonomy::editableOnly()->args() + ); + $this->assertSame( [ 'label' => 'Degrees',