From 497294906a4267643db7dc35286caa42c8378a3a Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 4 Nov 2024 15:57:27 +0100 Subject: [PATCH 1/2] Ability to hide collections from CP --- src/BaseCollection.php | 5 +++++ src/Repositories/CollectionRepository.php | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/BaseCollection.php b/src/BaseCollection.php index 49f6632..1b841b4 100644 --- a/src/BaseCollection.php +++ b/src/BaseCollection.php @@ -54,6 +54,11 @@ abstract public function futureDateBehavior(): ?string; abstract public function pastDateBehavior(): ?string; + public function visible(): bool + { + return true; + } + public function register() { $collection = StatamicCollection::make($this->handle()) diff --git a/src/Repositories/CollectionRepository.php b/src/Repositories/CollectionRepository.php index 2ef9350..67d5508 100644 --- a/src/Repositories/CollectionRepository.php +++ b/src/Repositories/CollectionRepository.php @@ -49,10 +49,10 @@ public function getCollectionByHandle($handle): ?BaseCollection public function all(): IlluminateCollection { $keys = $this->store->paths()->keys(); - + // add custom collections - $keys = $this->collections->keys()->merge($keys); - + $keys = $this->collections->keys()->filter(fn($collection) => $this->getCollectionByHandle($collection)->visible())->merge($keys); + return $this->store->getItems($keys, $this->collections); } From 59cf18fac93f0e19f05100ad1b57fc702fb98d96 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 4 Nov 2024 16:04:08 +0100 Subject: [PATCH 2/2] Pint --- src/Repositories/CollectionRepository.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Repositories/CollectionRepository.php b/src/Repositories/CollectionRepository.php index 67d5508..3cb421e 100644 --- a/src/Repositories/CollectionRepository.php +++ b/src/Repositories/CollectionRepository.php @@ -49,10 +49,10 @@ public function getCollectionByHandle($handle): ?BaseCollection public function all(): IlluminateCollection { $keys = $this->store->paths()->keys(); - + // add custom collections - $keys = $this->collections->keys()->filter(fn($collection) => $this->getCollectionByHandle($collection)->visible())->merge($keys); - + $keys = $this->collections->keys()->filter(fn ($collection) => $this->getCollectionByHandle($collection)->visible())->merge($keys); + return $this->store->getItems($keys, $this->collections); }