F
Filament2mo ago
CGM

Moving Sub-Navigation Elements to Main Sidebar as Child Elements

I've been working on integrating a new Relation Page into our project, following the guide in the docs (https://filamentphp.com/docs/3.x/panels/resources/relation-managers#relation-pages). However, I'm struggling to get the sub-navigation to our standard sidebar instead of in the content pane. I've been using the getRecordSubNavigation() method to generate the navigation items, as shown below:
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ViewLocation::class,
Pages\ManageReviewSites::class,
]);
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ViewLocation::class,
Pages\ManageReviewSites::class,
]);
}
The Pages\ManageReviewSites::class represents our Relation Page. What I'm aiming for is to have this 'sub-navigation' appear in the main sidebar instead when its parent page is accessed. I've attempted to modify the protected static SubNavigationPosition $subNavigationPosition, but my only options are top/start/end, nothing that indicates moving it to the main sidebar. I feel like getRecordSubNavigation() isn't the correct way to accomplish this. The attached screenshot kind of shows what I'm hoping to accomplish.
No description
Solution:
Have you try register custom navigation ?
No description
Jump to solution
3 Replies
Solution
Expecto Patronum
Have you try register custom navigation ?
No description
Dennis Koch
Dennis Koch2mo ago
Your are looking for „parent navigation items“
CGM
CGM2mo ago
I feel like I'm getting closer. How do I access the record/model in the URL from the custom navigation? My link in this example is http://foobar.localhost/portal/locations/9c0935b9-6522-456b-9e05-1959a2eca2ab/review-sites (from the screenshot). I need to pass the "locations record" to the navigation so it knows which URL to build.
NavigationItem::make('reviewSites')
->label(fn (): string => 'Review Sites')
->url(fn (): string => ManageReviewSites::getUrl(<What Goes Here?>)),
NavigationItem::make('reviewSites')
->label(fn (): string => 'Review Sites')
->url(fn (): string => ManageReviewSites::getUrl(<What Goes Here?>)),
My specific error is: Missing required parameter for [Route: filament.portal.resources.locations.reviewSites] [URI: portal/locations/{record}/review-sites] [Missing parameter: record]. I'm just not sure how to access this from the PanelProivder. As a side note, I tried making the ManageRelatedRecords use the protected static ?string $navigationParentItem = 'Locations'; without any luck, it is not visible, nor does it throw any errors. ----- Ok, a little progress, but it feels really wrong.
NavigationItem::make('reviewSites')
->label(fn (): string => 'Review Sites')
->url(fn (): string => ManageReviewSites::getUrl(['record' => request('record')]))
->icon('heroicon-o-presentation-chart-line')
->visible(fn () => strpos(request()->path(), 'portal/locations/') === 0)
->isActiveWhen(fn () => request()->path() === 'portal/locations/' . request('record') . '/review-sites'),
NavigationItem::make('reviewSites')
->label(fn (): string => 'Review Sites')
->url(fn (): string => ManageReviewSites::getUrl(['record' => request('record')]))
->icon('heroicon-o-presentation-chart-line')
->visible(fn () => strpos(request()->path(), 'portal/locations/') === 0)
->isActiveWhen(fn () => request()->path() === 'portal/locations/' . request('record') . '/review-sites'),
There has to be a better way. In particular the hard-coding in visible() and isActiveWhen(). Is there somewhere else I can put this? for example in my relation manager page for example? Ok, a little more progress:
->isActiveWhen(fn () => Route::currentRouteName() === 'filament.portal.resources.locations.reviewSites')
->isActiveWhen(fn () => Route::currentRouteName() === 'filament.portal.resources.locations.reviewSites')
Registering the custom nav ended up being the path I took. Thank you @Expecto Patronum