Cluster, subNav, add the CreateRecord action page to parent

This seems simple enough that I should've been able to search it, but because of the common terms it's not been getting me anywhere. I have a Cluster, it's subNav has two modules, for each I'd like to add a simple "New $record" button under it. I've tried protected static bool $shouldRegisterNavigation = true; in pages/Create$Model.php, as well as Setting the navigationGroup but the Create page doesn't show (although the List page does as per UserResource). Also the subnav isn't respecting collapsible(false) on the navigationgroup::make. Thanks!
3 Replies
πŸ…Έ πŸ…°πŸ…Ό πŸ…³πŸ…°πŸ…³πŸ…ΌπŸ…ΈπŸ…½
Okay, so some progress. 1. NavigationGroup definitions on $panel are ignored in the cluster (I assume this is intentional?) 2. In the Cluster definition I can override public static function getClusteredComponents(): array to return the Resource::class and Create$Model::class and that'll generate navItems, I still need to go into my Resource and Create page and set protected static ?string $navigationGroup, navIcon, navOrder etc etc however doing it this way means I can't set the GroupIcon or set collapsible(false). Okay, I am really lost with this, if I override getClusteredComponents in the Cluster class, I get my List/Create menuitems for the two Resources. If I try to override getSubNavigation I can instantiate the class in tinker and dd($cluster->getCachedSubNavigation()); and it shows the groups with collapsible false set, but ultimately the databind to the page doesn't seem to make it. I am assuming that somewhere else the getSubNavigation is overridden and uses the getClusteredComponents from the Cluster, but does not use the getSubNavigation from Cluster. Would appreciate any suggestions! I am surprising myself how far I am getting but definitely feel like I am missing something
awcodes
awcodesβ€’4w ago
I’d say check the blade component too. There may be some overrides there for design reasons.
πŸ…Έ πŸ…°πŸ…Ό πŸ…³πŸ…°πŸ…³πŸ…ΌπŸ…ΈπŸ…½
Thanks, the blade is set up to respect the prop for collapsible(false|true), it just doesn't seem to receive it. I'm going to see about setting the blade file to dump the contents of props to the debug log and see what it actually gets sent, and try to trace that down Okay, so I went into the blade vendor/filament/filament/src/../resources/views/components/page/sub-navigation/sidebar.blade.php and added @dump($navigation) and #isCollapsible: null not false or true Comparing setting getClusteredComponents only, setting getSubNavigation only and setting both, I can tell that only getClusteredComponents and the navgroup properties set in those classes is changing anything. That means that the getSubNavigation() method in panels/src/Clusters/Cluster.php is actually not doing anything at all, hence overriding it makes no difference Cool, so I figured it out. trait HasSubNavigation has a method public function getCachedSubNavigation(): array which constructs the Nav from scratch based on the values passed to it, and does not honour, or even set at all, the collapsible method, when a qualified NavigationGroup is passed. One possibility, is to override getCachedSubNavigation in the Cluster class and either hardcode collapsible to false or add code to make it honour all methods. The downside to doing it this way is that if you have added the cluster subnav to your create/view/edit pages, they will also need the getCachedSubNavigation amended. So better, is probably to manually edit the Trait filament/packages/panels/src/Pages/Concerns/HasSubNavigation.php with the fix to avoid all of that. I'll also open an issue on the GitHub and submit a PR for a hopefully non-breaking fix. It does however look like the SubNav trait and implementation is quite messy. It doesn't use NavigationManager or NavigationBuilder. I'll raise a separate issue on GitHub to discuss that. Either it might be worth having HasSubNavigation trait applied at the panel level so it can be configured on $panel or applied on a Cluster, and update the Cluster generator to include the trait on the generated class <List|Create|etc>$Model extends <List|Create|etc>Records classes

Did you find this page helpful?