Skip to content

Setting filters in sidebar links does not work well with the selected item #7634

@gremo

Description

@gremo

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:

  1. Strict equality check fails
  2. str_ends_with check fails

Has anyone managed to solve this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions