Problem/Motivation

In custom layout situations where the region content appears in a structure like this:

<div {{ region_attributes.first }}>
  <div>
    {{ content.first }}
  </div>
</div>

The Drag-and-drop reordering doesn't work because the selector takes .js-layout-builder-region > .js-layout-builder-block instead of .js-layout-builder-region .js-layout-builder-block.

Steps to reproduce

  1. Install latest version of Drupal 11 using the standard profile.
  2. Create layout builder sections for the Article content type.
  3. Create blocks nested several levels deep as shown above.
  4. Attempt to drag reorder the blocks.

Proposed resolution

TBD

Remaining tasks

  • Create a new MR based on Drupal 11.x
  • Copy code from the old MR's to the new one (or apply patches) and refactor where necessary
  • Hide the old MR's so the focus is on the new one
  • Refactor existing test coverage

User interface changes

TBD

API changes

TBD

Data model changes

N/A

Release notes snippet

TBD

Issue fork drupal-3062742

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

pinkdexo created an issue. See original summary.

dejanp’s picture

Status: Active » Needs review
StatusFileSize
new1.13 KB

I think this shouldn't break anything.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

dejanp’s picture

StatusFileSize
new2.21 KB

Because of the deprecation of the jQuery UI library, this patch applies to Drupal 8.8.x and above.

tim.plunkett’s picture

Issue tags: +Blocks-Layouts, +Needs tests

Is this something that could be tested with a functional JS test?

tim.plunkett’s picture

Status: Needs review » Needs work
andrimont’s picture

This is great, thank you @pinkdexo
It helps me to save the use of the layout of the TheMag theme -a great work-.
In my case Drupal 8.8.4 I used the #4 patch.
Success to get back the useful drag and drop !

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

dejanp’s picture

StatusFileSize
new2.24 KB

This is an updated patch that works with D9. It could be tested with functional JS but not sure how to do that because it requires a specific template structure - shown in comment #1.

djsagar’s picture

As Patch is created for above issue i changed the status need work to need review.

djsagar’s picture

Status: Needs work » Needs review
TylerMarshall’s picture

This patch (tested the 8.9.x) works flawlessly for me.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

benstallings’s picture

Status: Needs review » Reviewed & tested by the community

Patch #10 works for me, too.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work

Glad it's working! Now just for the automated test coverage...

naveen433’s picture

Assigned: Unassigned » naveen433

I am working on this

naveen433’s picture

Assigned: naveen433 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.97 KB
new2.45 KB

check the drupal standards

gauravvvv’s picture

StatusFileSize
new4.47 KB
new512 bytes

Re-rolled patch #18, Attached interdiff for same.

ranjith_kumar_k_u’s picture

StatusFileSize
new5.33 KB

Fixed custom command failure

Status: Needs review » Needs work

The last submitted patch, 20: 3062742-20.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Needs review
StatusFileSize
new5.78 KB

I tried writing tests for this and boy was it hard! I have a partial test in this patch. I don't know how to make it any better.

The problems I had were:

1. SortableTestTrait::sortableTo() only simulates a drag and does actually have the browser perform drag and drop.
2. For some reason I don't understand, NodeElement::dragTo() wasn't working for LB blocks, even with the default templates.

This is just a new fail test, so no interdiff.

danflanagan8’s picture

StatusFileSize
new5.78 KB

Sorry...Here's another.

Status: Needs review » Needs work

The last submitted patch, 23: 3062742-23-FAIL.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Needs review
StatusFileSize
new8.03 KB
new9.02 KB

That failed exactly as expected. Clicking the body block did not trigger any sort of "sortable" behavior. Here's the fail patch with the fix from #10 added.

NOTE: Ignore that interdiff. The correct one is attached to #26.

danflanagan8’s picture

StatusFileSize
new2.25 KB

Ignore that interdiff. Oof.

Here's the real interdiff, which is simply the fix from #10.

danflanagan8’s picture

Aha! Here's why my attempts to use NodeElement::dragTo() weren't working. Per the SortableTestTrait:

* Selenium uses ChromeDriver for FunctionalJavascript tests, but it does not
* currently support HTML5 drag and drop. These methods manipulate the DOM.
* This trait should be deprecated when the Chromium bug is fixed.

This is tracked in an issue: #3078152: Follow-up to #3064049 Deprecate sortable Trait.

I'm pretty sure we can't make a good test for this issue until Chromium supports html5 drag and drop. I say that because the following test runs flawlessly on 9.3.x.

/**
   * Tests the Layout Builder UI with extra wrapper divs in template.
   */
  public function testLayoutBuilderCustomTemplate() {
    // Override the layout templates.
    \Drupal::service('module_installer')->install(['layout_builder_custom_template_test']);
    \Drupal::service('plugin.manager.core.layout')->clearCachedDefinitions();
    \Drupal::service('theme_handler')->refreshInfo();
    $this->testLayoutBuilderUi();
  }

That is, big existing test does not fail with the custom templates featuring extra wrapping divs.

I think the wisest move would be to postpone this issue until the Chromedriver bug is fixed. To me it looks like there's no existing robust test coverage of LB drag-and-drop, which makes changes really risky!

That said, anyone running into this bug will probably be ok with the patch in #10.

The fail patch from #23 will be easy to update when we can do real dragging, so that's a good start.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

TylerMarshall’s picture

Status: Needs review » Reviewed & tested by the community

Thank you thank you thank you!

Patch 25 works for me just fine! I can RTBC!

danflanagan8’s picture

Status: Reviewed & tested by the community » Needs work

This still needs tests, so back to NW.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

heikkiy’s picture

StatusFileSize
new13 MB

We are seeing this same bug with Drupal core 9.4.8 and following contrib modules:
- Field group 8.x-3.3
- UI Patterns 8.x-1.3.

We have a content display mode with multiple regions

Regions are something like:
- Header
- Main content
- Footer

When I create a field group inside the region, the drag breaks completely.

There is also a related issue in Field group: https://www.drupal.org/project/field_group/issues/3085858.

I have tried the patches from issues 3089151, 3087608 and this one. It seems it gets a little bit better and with trial and error I can get the field to stay in a correct region. But sometimes it just resets. Here is a attached video recording of what happens when I drag multiple times and then save.

Without the patches, the dragging is completely broken and you cannot even stop the drag. The field you are dragging just keeps following you. With the patch from issue 3087608 the dragging works a bit better but it let's me let go of dragging. But after saving the form, the region is still reset.

Without the patches the functionality seemed to be that if I try to drag the field to a region, it gets assigned to the first available region instead of the one I would like to drag the field to. I have tested this with Claro, Gin and Seven admin themes.

bernardm28 made their first commit to this issue’s fork.

bernardm28’s picture

StatusFileSize
new1.5 KB

Rerolls the patch to make it compatible with 9.5

ctrlADel made their first commit to this issue’s fork.

ctrladel’s picture

Looked like the reroll was missing the tests that were in the patch from #25 so pushed those to both the 9.5 and 10 MRs

justskew’s picture

StatusFileSize
new3.12 KB

Fixed for drupal/core:9.5.3

zeeshan_khan’s picture

Status: Needs work » Needs review
StatusFileSize
new2.63 KB
new1.88 KB

Patch rerolled for 9.5.x
Added reroll diff.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

Was previously tagged for tests which still need to happen.

Also issue summary could use some updating.

Thanks.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

weseze’s picture

StatusFileSize
new1.1 KB

Rerolled for D10.1.x

xeiro’s picture

I can confirm #44 patch applies to D10.1.8

zeeshan_khan’s picture

@weseze - Please provide interdiff
Also we need a re-roll for 11.x

tlo405’s picture

Patches here aren't working for me with a setup like this:

<div class="layout-builder__region js-layout-builder-region layout__region">
  <div class="js-layout-builder-block layout-builder-block">Block 1</div>
  <div class="js-layout-builder-block layout-builder-block">Block 2</div>
  <div class="js-layout-builder-block layout-builder-block">Block 3</div>
  <div class="my-custom-wrapper-here">
    <div class="js-layout-builder-block layout-builder-block">Block 4</div>
    <div class="js-layout-builder-block layout-builder-block">Block 5</div>
  </div>
</div>

It sounds like I should expect to be able to drag and drop 'Block 4' and 'Block 5' around after applying some of the patches here, however I am unable to. My custom wrapper breaks the layout builder drag+drop functionality.

From the original post:

The Drag-and-drop reordering doesn't work because the selector takes .js-layout-builder-region > .js-layout-builder-block instead of .js-layout-builder-region .js-layout-builder-block.

Is something incorrect with my formatting perhaps? Seems like what I have should work?

grimreaper’s picture

Hi,

Thanks for all the work done on this issue.

Patch from comment 44 applies on Core 10.3.1 and fixes the issue for me. I have a layout with multiple levels of nesting mixed with other sections with "standards" layouts and now it works perfectly.

https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...

Where:
- <div{{ attributes.addClass('accordion-item') }}> is the region div.
- {{ content }} is the region content

heykarthikwithu’s picture

StatusFileSize
new1.25 KB

#44 was not working in my case, made change suggested in #47, works for me (attached the patch)

weseze’s picture

StatusFileSize
new680 bytes

Patch #44 no longer applies to D11.2
Patch #49 does not work for us, it seems te create a direct parent-child requirement between the regions and the blocks (which is what we set out to avoid?)

Rerolled patch #44 to work against D11.2 and attached it here.

weseze’s picture

StatusFileSize
new1.29 KB

UPDATE:

So patch #44 was previously working for us. (Drupal 10.1.x through 10.3.x)
Since updating to Drupal 11 (11.2.5 in our case), patch no longer applies.
I tried patch from #49, it did apply, but wasn't working for us. Could not initiate the dragging.

My updated patch from #50 did apply and drag-and-drop was visually working, but the order was not saved.

So, here is an updated patch that actually works for us now.
The trick is to pass the direct parent to the sortable plugin (which is technically not correct, but can be handled in the "dragged" function.

Regarding the comment in #47: I don't think that can ever work correctly since Sortable assumes direct children for the sortable items. Having items in 2 different levels assumes nested sortables. That't something much more complex to implement according to the documentation... (I could be wrong)

oily’s picture

Issue summary: View changes
oily’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.