craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 637 forks source link

[5.x]: `fillGapsInElements` not getting all elements #16085

Closed white-lukas closed 1 week ago

white-lukas commented 2 weeks ago

What happened?

Description

When trying to get all structure elements from an array of elements, The fillGapsInElements is not returning all elements from the structure, it's depending on the sort order of the given elements.

Example: when passing in 2 elements into the function with the following structure:

  1. fietsen/heren/starters-racefiets/starters-racefiets
  2. fietsen/racefietsen/starters-racefiets

The lft value of the first element is 117, the second 14

When passing the elements in this order the returned array is missing the fietsen/racefietsen entry.

When I would change the order of the passed in elements the fietsen/racefietsen entry is returned as well

Craft CMS version

5.4.10.1

PHP version

8.3.13

Operating system and version

Ubuntu 24.04

Database type and version

mysql 8.0

Image driver and version

No response

Installed plugins and versions

-

i-just commented 1 week ago

Hi, thanks for reaching out. Let me first double check if I understand this correctly. Your structure looks something like that: -- racefietsen ------ starters racefiets -- heren ------ starters racefiets ---------- starters racefiets

And you're saying that if you pass [<heren/starters-racefiets/starters-racefiets>, <racefietsen/starters-racefiets>] to the fillGapsInElements(), you get back 4 of the above mentioned elements:

And if you flip the order and pass [<racefietsen/starters-racefiets>, <heren/starters-racefiets/starters-racefiets>], you get back all 5 of the above mentioned elements:

Is that correct?

white-lukas commented 1 week ago

complete structure is

Image

When passing in [<heren/starters-racefiets/starters-racefiets>, <racefietsen/starters-racefiets>] I miss the fietsen/racefietsen category, as then this is getting added and filters out the lower lft value of the racefietsen/starters-racefiets entry

i-just commented 1 week ago

Thanks for confirming. I raised a PR for this.

brandonkelly commented 1 week ago

Craft 4.13.3 and 5.5.1 are out with that fix. Thanks again!