My CRUD controller has a date filter, and I want to set a default value for it in my sidebar.
This works perfectly (as suggested by many in #3941):
public function configureMenuItems(): iterable
{
yield MenuItem::linkTo(WorkShiftCrudController::class, 'Work shifts', 'fa-solid fa-clock')
->setQueryParameter('filters[date][comparison]', '>=')
->setQueryParameter('filters[date][value]', date('Y-m-d', strtotime('yesterday')))
;
}
The problem is that the corresponding sidebar item remains selected only until the URL changes. As soon as the filter value is modified or the sorting is changed, the item becomes deselected.
This happens because of the logic used to determine the selected sidebar item in MenuItemMatcher, where the sidebar URL (which contains the filter parameter) is compared to the current URL in various ways, but none of them account for this use case.
The sidebar URL will be generated as follow:
$menuUrl = "admin/work-shift?filters%5Bdate%5D%5Bcomparison%5D=>%3D&filters%5Bdate%5D%5Bvalue%5D=2026-06-02"
Imagine you remove the date filter, then:
$currentUrlWithoutHostAndWithNormalizedQueryString = "admin/work-shift"
In MenuItemMatcher:
- Strict equality check fails
- str_ends_with check fails
Has anyone managed to solve this issue?
My CRUD controller has a date filter, and I want to set a default value for it in my sidebar.
This works perfectly (as suggested by many in #3941):
The problem is that the corresponding sidebar item remains selected only until the URL changes. As soon as the filter value is modified or the sorting is changed, the item becomes deselected.
This happens because of the logic used to determine the selected sidebar item in
MenuItemMatcher, where the sidebar URL (which contains the filter parameter) is compared to the current URL in various ways, but none of them account for this use case.The sidebar URL will be generated as follow:
Imagine you remove the date filter, then:
In
MenuItemMatcher:Has anyone managed to solve this issue?