From a9c11334f269402a72d7976c9523093a968d59af Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 22 Aug 2024 12:35:54 +0100 Subject: [PATCH 1/2] Hide term create button when all blueprints are hidden --- resources/views/taxonomies/show.blade.php | 4 ++-- src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php | 2 ++ src/Taxonomies/Taxonomy.php | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/resources/views/taxonomies/show.blade.php b/resources/views/taxonomies/show.blade.php index c2c3da0280..3aff3310d8 100644 --- a/resources/views/taxonomies/show.blade.php +++ b/resources/views/taxonomies/show.blade.php @@ -33,12 +33,12 @@ @endcan - @can('create', ['Statamic\Contracts\Taxonomies\Term', $taxonomy]) + @if($canCreate) - @endcan + @endif diff --git a/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php b/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php index 15b352d4a2..737658dccc 100644 --- a/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php +++ b/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php @@ -18,6 +18,7 @@ use Statamic\Stache\Repositories\TermRepository as StacheTermRepository; use Statamic\Support\Arr; use Statamic\Support\Str; +use Statamic\Contracts\Taxonomies\Term as TermContract; class TaxonomiesController extends CpController { @@ -80,6 +81,7 @@ public function show($taxonomy) 'taxonomy' => $taxonomy->handle(), 'blueprints' => $blueprints->pluck('handle')->all(), ]), + 'canCreate' => User::current()->can('create', [TermContract::class, $taxonomy]) && $taxonomy->hasVisibleTermBlueprint(), ]; if ($taxonomy->queryTerms()->count() === 0) { diff --git a/src/Taxonomies/Taxonomy.php b/src/Taxonomies/Taxonomy.php index f3fa2c6cb8..8c61204c02 100644 --- a/src/Taxonomies/Taxonomy.php +++ b/src/Taxonomies/Taxonomy.php @@ -166,6 +166,11 @@ public function fallbackTermBlueprint() return $blueprint; } + public function hasVisibleTermBlueprint() + { + return $this->termBlueprints()->reject->hidden()->isNotEmpty(); + } + public function sortField() { return 'title'; // todo From 84dc95640b72cb6b0ee55a4bd067de510a6a1b3e Mon Sep 17 00:00:00 2001 From: duncanmcclean Date: Thu, 22 Aug 2024 11:37:35 +0000 Subject: [PATCH 2/2] Fix styling --- src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php b/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php index 737658dccc..7c6c2550b5 100644 --- a/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php +++ b/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php @@ -4,6 +4,7 @@ use Illuminate\Http\Request; use Statamic\Contracts\Taxonomies\Taxonomy as TaxonomyContract; +use Statamic\Contracts\Taxonomies\Term as TermContract; use Statamic\Contracts\Taxonomies\TermRepository; use Statamic\CP\Column; use Statamic\Facades\Blueprint; @@ -18,7 +19,6 @@ use Statamic\Stache\Repositories\TermRepository as StacheTermRepository; use Statamic\Support\Arr; use Statamic\Support\Str; -use Statamic\Contracts\Taxonomies\Term as TermContract; class TaxonomiesController extends CpController {