Order of rows on hierarchy children form is wrong

Created on 21 June 2021, over 3 years ago
Updated 18 July 2024, 3 months ago

Problem/Motivation

When sorting child items on the hierarchy children form, the order they are displayed in (even after dragging\changing weights and saving) is always that of the order in which they are added to the render array.

Steps to reproduce

Create a hierarchy, and attempt to reorder the children of one node. After saving the order, they revert to their default order in the form.

Proposed resolution

There's 2 things happening here;

  1. In \Drupal\entity_hierarchy\Form\HierarchyChildrenForm::form The weight used in the row #weight key is wrong. The foreach that loops over the nodes assumes the key is the weight, but this is actually just the index since $children is just an array.
  2. Even if 1 is fixed, there is a core issue that prevents table rows from being sorted correctly if their weight is set. See core issue 2396923 . Patch #9 in that issue resolved the problem for us (at least in Drupal 8.9.16).

Attached is a patch that corrects point 1. Together with the core patch mentioned in point 2 we can successfully reorder children and have their order stay correct in the form.

🐛 Bug report
Status

Active

Version

3.0

Component

Code (module)

Created by

🇳🇱Netherlands dennis_meuwissen

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia acbramley

    Encountered this too, the order of the children rows does not match their weight.

    The children form does have a #weight element, but it's set to the delta from the children. The order of the children from $storage->findChildren is based on the left_pos, not the weight.

    Even if the #weight element was set to the correct weight, the elements still need sorting (since findChildren does not return items in the correct order).

    I will work on a failing test for this.

  • 🇦🇺Australia acbramley

    I'm trying to reproduce this in a test but I'm not able to. This popped up for us during a migration. Running the rebuild tree drush command has fixed it though so I'm a bit confused if/how to get it failing in a test.

  • Merge request !44Draft: Resolve #3219844 "Order of rows" → (Open) created by acbramley
  • Pipeline finished with Failed
    3 months ago
    Total: 294s
    #227407
Production build 0.71.5 2024