diff --git a/docs/06-navigation/03-user-menu.md b/docs/06-navigation/03-user-menu.md index f8147cdeae..df03e49f03 100644 --- a/docs/06-navigation/03-user-menu.md +++ b/docs/06-navigation/03-user-menu.md @@ -94,3 +94,18 @@ Action::make('lockSession') ->url(fn (): string => route('lock-session')) ->postToUrl() ``` + +## Disabling the user menu + +You may disable the user menu entirely by passing `false` to the `userMenu()` method: + +```php +use Filament\Panel; + +public function panel(Panel $panel): Panel +{ + return $panel + // ... + ->userMenu(false); +} +``` diff --git a/packages/panels/resources/views/components/layout/simple.blade.php b/packages/panels/resources/views/components/layout/simple.blade.php index 48e7e5d12d..0daa92627f 100644 --- a/packages/panels/resources/views/components/layout/simple.blade.php +++ b/packages/panels/resources/views/components/layout/simple.blade.php @@ -26,7 +26,9 @@ ]) @endif - @livewire(Filament\Livewire\SimpleUserMenu::class) + @if (filament()->hasUserMenu()) + @livewire(Filament\Livewire\SimpleUserMenu::class) + @endif @endif diff --git a/packages/panels/resources/views/livewire/topbar.blade.php b/packages/panels/resources/views/livewire/topbar.blade.php index 14458956f3..2120a60a3c 100644 --- a/packages/panels/resources/views/livewire/topbar.blade.php +++ b/packages/panels/resources/views/livewire/topbar.blade.php @@ -224,7 +224,9 @@ ]) @endif - + @if (filament()->hasUserMenu()) + + @endif @endif diff --git a/packages/panels/src/Facades/Filament.php b/packages/panels/src/Facades/Filament.php index 1f7a56c58a..6c07072e79 100644 --- a/packages/panels/src/Facades/Filament.php +++ b/packages/panels/src/Facades/Filament.php @@ -133,6 +133,8 @@ use Illuminate\Support\Facades\Facade; * @method static bool hasTenantMenu() * @method static bool hasTenantProfile() * @method static bool hasTenantRegistration() + * @method static bool hasTopbar() + * @method static bool hasUserMenu() * @method static bool hasTopNavigation() * @method static bool hasUnsavedChangesAlerts() * @method static bool isAuthorizationStrict() diff --git a/packages/panels/src/FilamentManager.php b/packages/panels/src/FilamentManager.php index 0b059a6cd9..ec6762c7f1 100644 --- a/packages/panels/src/FilamentManager.php +++ b/packages/panels/src/FilamentManager.php @@ -730,6 +730,11 @@ class FilamentManager return $this->getCurrentOrDefaultPanel()->hasTopbar(); } + public function hasUserMenu(): bool + { + return $this->getCurrentOrDefaultPanel()->hasUserMenu(); + } + public function hasTopNavigation(): bool { return $this->getCurrentOrDefaultPanel()->hasTopNavigation(); diff --git a/packages/panels/src/Panel/Concerns/HasUserMenu.php b/packages/panels/src/Panel/Concerns/HasUserMenu.php index 2f7817784e..6da537f196 100644 --- a/packages/panels/src/Panel/Concerns/HasUserMenu.php +++ b/packages/panels/src/Panel/Concerns/HasUserMenu.php @@ -12,11 +12,20 @@ use Illuminate\Support\Collection; trait HasUserMenu { + protected bool | Closure $hasUserMenu = true; + /** * @var array */ protected array $userMenuItems = []; + public function userMenu(bool | Closure $condition = true): static + { + $this->hasUserMenu = $condition; + + return $this; + } + /** * @param array $items */ @@ -30,6 +39,11 @@ trait HasUserMenu return $this; } + public function hasUserMenu(): bool + { + return (bool) $this->evaluate($this->hasUserMenu); + } + protected function getUserProfileMenuItem(Action | Closure | MenuItem | null $item = null): Action { $page = Filament::getProfilePage();