Merge pull request #16194 from binaryfire/disable-user-menu

This commit is contained in:
Dan Harrin
2025-05-04 16:50:10 +01:00
committed by GitHub
6 changed files with 42 additions and 2 deletions
+15
View File
@@ -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);
}
```
@@ -26,7 +26,9 @@
])
@endif
@livewire(Filament\Livewire\SimpleUserMenu::class)
@if (filament()->hasUserMenu())
@livewire(Filament\Livewire\SimpleUserMenu::class)
@endif
</div>
@endif
@@ -224,7 +224,9 @@
])
@endif
<x-filament-panels::user-menu />
@if (filament()->hasUserMenu())
<x-filament-panels::user-menu />
@endif
@endif
</div>
+2
View File
@@ -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()
+5
View File
@@ -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();
@@ -12,11 +12,20 @@ use Illuminate\Support\Collection;
trait HasUserMenu
{
protected bool | Closure $hasUserMenu = true;
/**
* @var array<Action | Closure | MenuItem>
*/
protected array $userMenuItems = [];
public function userMenu(bool | Closure $condition = true): static
{
$this->hasUserMenu = $condition;
return $this;
}
/**
* @param array<Action | Closure | MenuItem> $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();