From 7d4f506af309034be25e87c37cdf28cf12fbfd59 Mon Sep 17 00:00:00 2001 From: Schilly Date: Mon, 25 Nov 2024 14:21:22 -0500 Subject: [PATCH 1/2] Add ability to hide the resource from navigation menu based on panel ID --- config/filament-types.php | 11 +++++++---- src/Filament/Resources/TypeResource.php | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/config/filament-types.php b/config/filament-types.php index 8249877..578d8ff 100644 --- a/config/filament-types.php +++ b/config/filament-types.php @@ -16,11 +16,14 @@ 'types_resource' => null, /** - * Show Navigation Menu - * - * If you need to show the navigation menu for the types + * Panel Navigation + * Accepts: boolean OR array of panel ID with boolean + * If array is empty, assumes to not display navigation item. + * + * Panel Example: + * 'panel_navigation' => ['admin' => TRUE]; */ - 'show_navigation' => true, + 'panel_navigation' => true, /** * Empty State diff --git a/src/Filament/Resources/TypeResource.php b/src/Filament/Resources/TypeResource.php index b6598f8..ac28b13 100644 --- a/src/Filament/Resources/TypeResource.php +++ b/src/Filament/Resources/TypeResource.php @@ -43,6 +43,29 @@ public static function getNavigationGroup(): ?string return trans('filament-types::messages.group'); } + /** + * Config Item: `panel_navigation` + * Returns: bool + * + * Accepts: array OR bool + * + * Compares against current panel ID based on what is in the array (if provided). + */ + public static function shouldRegisterNavigation(): bool + { + $configItem = config('filament-types.panel_navigation', TRUE); + + if (is_array($configItem) && !empty($configItem)) { + foreach (config('filament-types.panel_navigation', true) as $key => $val) { + if (Filament::getCurrentPanel()->getId() === $key) { + return $val; + } + } + } else { + return (empty($configItem)) ? FALSE : $configItem; + } + } + public static function form(Form $form): Form { return TypeForm::make($form); From f152c85a5a6360ba691e8d4f8380de5def95d540 Mon Sep 17 00:00:00 2001 From: Schilly Date: Mon, 25 Nov 2024 14:37:18 -0500 Subject: [PATCH 2/2] bug fix --- src/Filament/Resources/TypeResource.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Filament/Resources/TypeResource.php b/src/Filament/Resources/TypeResource.php index ac28b13..c67b5e6 100644 --- a/src/Filament/Resources/TypeResource.php +++ b/src/Filament/Resources/TypeResource.php @@ -9,6 +9,7 @@ use TomatoPHP\FilamentTypes\Filament\Resources\TypeResource\Form\TypeForm; use TomatoPHP\FilamentTypes\Filament\Resources\TypeResource\Table\TypeTable; use TomatoPHP\FilamentTypes\Models\Type; +use Filament\Facades\Filament; class TypeResource extends Resource { @@ -59,6 +60,8 @@ public static function shouldRegisterNavigation(): bool foreach (config('filament-types.panel_navigation', true) as $key => $val) { if (Filament::getCurrentPanel()->getId() === $key) { return $val; + } else { + return FALSE; } } } else {