b13/container

Bug with sorting content elements after containers

koehnlein opened this issue · 3 comments

Hi have a page with a lot of content elements, some inside containers and some outside containers. And I have found the following bug:

When I want to sort an element after a container, or create a new content element after the container, the calculated new sorting value, is based on the sorting of the inner content element instead of the container.

The problem seems to be this code

if (empty($childRecords)) {
where you handle containers with content differently than empty containers.

See this example. We want to move "Content Element 2" after the container. In the mentioned code, the check if (empty($childRecords)) would fail, because there are children. This would cause, the last child will be returned and used for sorting. And this would be cause that the new sorting value would be calculated based on 256 instead of 4608. And this would cause, the element would not be placed after the container but somewhere else.

+ Content Element 1, sorting 4096

+ Content Element 2, sorting 4352

+ Container, sorting 4608
   + Content Element 3, sorting 256

+ .... here I want to place the content element ....

See also this short video clip where I show the problem: Link to MP4 video

@koehnlein did you run the container.sorting --apply command (s. https://github.com/b13/container/releases/tag/2.0.0) looks your "Content Element 3, sorting 256" is wrong, because it should be sorted after "Container, sorting 4608"

@achimfritz Thanks, that helped! Would you recommend to regularly execute it? Or should everything be fine after doing it once.

regularly execution is not required. (as long as no other sorting bug appears)