Problem/Motivation

LayoutParagraphsLayout::reorderComponents() rebuilds the whole field value from the list of components the browser posts, and drops every component that is not in it.

js/builder.js builds that list from the DOM, so it only holds the components the builder rendered. A component in a region its section's layout does not have is rendered neither by the builder nor on the front end. The first reorder anywhere in the builder, by drag or with the move buttons, then removes it from the field. Once the host is saved it is gone for good: switching the section back to the original layout does not bring it back.

One way to get such a component is described in #3375164 (switching a section from three columns to two). The reorder path should not turn an invisible component into a deleted one, however it got there.

Steps to reproduce

  1. Add a three-column section with a component in the first region and another in the third, and save.
  2. Change the section's layout to two columns in a way that leaves the third region's component in place (for example the steps in #3375164), and save.
  3. Open the builder, move any other component, and save.
  4. The component that was in the third region is no longer referenced by the field.

Proposed resolution

In reorderComponents(), keep the components that are missing from the posted order, in their existing order, after the ones that were listed.

Nothing deletes a component through reorderComponents(): deletion has its own path, LayoutParagraphsLayout::deleteComponent(), used by the delete, convert and duplicate forms. So keeping unlisted components does not bring back deleted ones.

The merge request adds a Kernel test for reorderComponents() and a Cypress test that strands a component, moves another one with the move up button and checks that the stranded one is still in the field. Both fail without the fix.

Remaining tasks

  • Review.

User interface changes

None.

API changes

None. reorderComponents() keeps components it previously removed.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tiago created an issue. See original summary.

tiago’s picture

Status: Active » Needs review
StatusFileSize
new8.27 KB

MR !276 keeps the components that are missing from the posted order, after the listed ones. It adds a Kernel test for reorderComponents() and a Cypress test that strands a component and reorders another one.

I have also attached the patch file here.

  • justin2pin committed c8beb25e on 3.0.x
    Issue #3627088: Keep the components missing from the order when...
justin2pin’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.