Skip to content

Commit

Permalink
Add ability to hide the resource from navigation menu based on panel ID
Browse files Browse the repository at this point in the history
  • Loading branch information
pschilly committed Nov 25, 2024
1 parent a3901ff commit 7d4f506
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
11 changes: 7 additions & 4 deletions config/filament-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/Filament/Resources/TypeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7d4f506

Please sign in to comment.