Filtering by Single Parent ID Also Returns Grandchildren

Created on 20 December 2023, 6 months ago

Problem/Motivation

Not sure if this is the expected behavior, but when filtering by a single parent id, it will return children and grandchildren.

Steps to reproduce

Example menu

  • Menu Item 1
    • Menu Item 2
    • Menu Item 3
    • Menu Item 4
      • Menu Item 5

Filtering example

?filter[parent]=menu_link_content:menu-item-1

This will return 4 results, including โ€œMenu Item 5โ€, which is not a direct child of โ€œMenu Item 1โ€, but a grandchild. My expectation was that if youโ€™re filtering by a single parent id, it would only return direct children, not grandchildren ?

You can work around this by also adding a max_depth of 1 to force only getting direct children:

?filter[parent]=menu_link_content:menu-item-1&filter[max_depth]=1

Proposed resolution

Should the default behavior be a max depth of 1 when filtering by a single parent id ? If the logic is give me all menu items where parent id = menu_link_content:menu-item-1, I wouldn't expect grandchild menu items to also be included. This default could be added, if we made the following change to applyFiltersToParams

if (!empty($filter['parent'])) {
  $parameters->setRoot($filter['parent']);
  $parameters->setMaxDepth(1);
  $parameters->excludeRoot();
}
๐Ÿ› Bug report
Status

Active

Version

1.2

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States wluisi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @wluisi
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    I think this is a documentation issue, just need to document that you need to pass max_depth in that scenario?

Production build 0.69.0 2024