F
Filamentβ€’6mo ago
Husky110

Navigation in groups with translated labels

Hi folks, I am struggling a bit on rebuilding my old v2-Frontend in v3. Right now I am trying to recreate the old navigation-structure which had been build using a NavigationBuilder. Here is the old code:
NavigationGroup::make(m__('navigation.articlemanagement'))->items([
...ArticleResource::getNavigationItems(),
...InvalidArticleResource::getNavigationItems(),
...StockproblemResource::getNavigationItems(),
NavigationGroup::make(m__('general.terms.tools'))->items([
NavigationItem::make(m__('articlemanagement.tools.batchtracing.navigationlabel'))
->icon('blossom-icons.articles.tools.batchtracing')
->url(Articleselection::getUrl())
->isActiveWhen(fn() => str_contains(request()->route()->getName(), 'batchtracing')),
...WarehousemanagementResource::getNavigationItems(),
])->collapsible(false),
])->collapsible(false),
NavigationGroup::make(m__('navigation.articlemanagement'))->items([
...ArticleResource::getNavigationItems(),
...InvalidArticleResource::getNavigationItems(),
...StockproblemResource::getNavigationItems(),
NavigationGroup::make(m__('general.terms.tools'))->items([
NavigationItem::make(m__('articlemanagement.tools.batchtracing.navigationlabel'))
->icon('blossom-icons.articles.tools.batchtracing')
->url(Articleselection::getUrl())
->isActiveWhen(fn() => str_contains(request()->route()->getName(), 'batchtracing')),
...WarehousemanagementResource::getNavigationItems(),
])->collapsible(false),
])->collapsible(false),
Important note: m__ is my custom translation-function. I am trying to follow the docs at https://filamentphp.com/docs/3.x/panels/navigation#grouping-navigation-items-under-other-items and came up with this so far in the PanelServiceProvider:
NavigationGroup::make()
->label(fn() => m__('navigation.articlemanagement'))
NavigationGroup::make()
->label(fn() => m__('navigation.articlemanagement'))
Now I am trying to add the WarehousemanagementResource and added this code to it:
public static function getNavigationParentItem(): ?string
{
return m__('navigation.articlemanagement');
}

public static function getNavigationGroup(): ?string
{
return m__('general.terms.tools');
}
public static function getNavigationParentItem(): ?string
{
return m__('navigation.articlemanagement');
}

public static function getNavigationGroup(): ?string
{
return m__('general.terms.tools');
}
But this always leaves me with an error Call to a member function keyBy() on null. I need to recreate the structure in the attached screenshot and I am confused that NavigationGroups are identified by their labels? How does that work with translations? Could someone please help me in this and tell me what's the best practice with the desired outcome please? πŸ™‚
No description
1 Reply
Husky110
Husky110β€’6mo ago
Okay - I was able to figure out that my error came from a mixup. The correct code for the WarehouseManagementResource should have been this:
public static function getNavigationParentItem(): ?string
{
return m__('general.terms.tools');
}

public static function getNavigationGroup(): ?string
{
return m__('navigation.articlemanagement');
}
public static function getNavigationParentItem(): ?string
{
return m__('general.terms.tools');
}

public static function getNavigationGroup(): ?string
{
return m__('navigation.articlemanagement');
}
Problem is - the Sub-Group does not show up on the navigation... I tried returning a static string return 'Tools'; but nothing shows up... push? πŸ™‚ @Patrick Boivin - Hey Pat, can you help me on this one please?