F
Filament7mo ago
Flo

Disable sub-navigation on specify page

Hello, is it possible to disable the sub-navigation resource on certain pages only? I have a resource that has a public function getRecordSubNavigation, but I want to hide it on a specific page of type ViewRecord. This page is not included in the menu, but I want to disable this menu for this page. Is it possible ?
Solution:
Ok, I have the solution. In the ViewRecord page, add this: ```php...
Jump to solution
7 Replies
DrByte
DrByte7mo ago
Can you post your getRecordSubNavigation code? Does inspecting the properties of the Page $page parameter allow you to conditionally change the values?
Flo
Flo7mo ago
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ListSitesServer::class,
Pages\DatabaseServer::class,
Pages\CronServer::class,
Pages\DaemonServer::class,
Pages\FirewallRulesServer::class,
Pages\BackupServer::class,
Pages\SoftwareServer::class,
Pages\FileServer::class,
Pages\LogServer::class,
Pages\EditServer::class,
]);
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ListSitesServer::class,
Pages\DatabaseServer::class,
Pages\CronServer::class,
Pages\DaemonServer::class,
Pages\FirewallRulesServer::class,
Pages\BackupServer::class,
Pages\SoftwareServer::class,
Pages\FileServer::class,
Pages\LogServer::class,
Pages\EditServer::class,
]);
}
On my ServerResource. As you see, there is no ViewProvisioningServer page. But on this page, the sub-navigation appears, which seems to be normal, but I would like to deactivate it right here.
DrByte
DrByte7mo ago
and if you dd($page) what do you get? I wonder if there's a property in there that could be used to exclude certain things? Or is there something in your ViewProvisioningServer class that can control when it's registered? ViewRecord has a parent shouldRegisterNavigation() which can be overridden.
Flo
Flo7mo ago
I tried with shouldRegisterNavigation() set to false in ViewProvisioningServer but the sub-navigation still appears. I think shouldRegisterNavigation() is just to display ViewProvisioningServer in the menu, but not to remove the menu itself. I haven't seen anything that could help me in dd($page)
Solution
Flo
Flo7mo ago
Ok, I have the solution. In the ViewRecord page, add this:
public function getSubNavigation(): array
{
return [];
}
public function getSubNavigation(): array
{
return [];
}
Flo
Flo7mo ago
thank you @DrByte for your time
DrByte
DrByte7mo ago
Yay! Glad you found it. I've done a lot of code-diving to find answers to similar questions: just keep following the features of the parent classes, and you can discover a lot of cool things!