Can't drag & drop

Created on 9 March 2020, over 5 years ago
Updated 2 September 2025, 11 days ago

Hello;

Unfortunately, when using this module with Layout Builder, the blocks inside a pattern cannot be dragged and dropped. This UI is one of the major advantages of layout builder, so I think the lack of it is a major drawback.

As far as i've found, this is a problem that involves many layers and can be difficult to solve:

  1. The main reason this is not working is because Layout builder uses some classes for drag & drop (mainly layout-builder__region and js-layout-builder-region).
  2. On core layouts, this classes are used on the {{ region_attributes }} of the layout templates. So, we'll need patterns to implement this
  3. But if you use them on a pattern template, you'll see they won't appear. Layout Discovery's template_preprocess_layout(&$variables) is the hook in charge of populating {{region_attributes}}. Right now it doesn't do it because the pattern layout definition is not ready when getThemeImplementations is called on layout_discovery_theme() (see this issue https://github.com/nuvoleweb/ui_patterns/pull/289), so they aren't affected by the hook. Applying the given patch solves this.
  4. Moreover, this module's processLayoutBuilderRegions() also needs to be modified because as it is now it will delete the #attributes of the element, which holds the region classes and is needed for this to work. A simple approach to quickly fix this is to iterate also on Element::properties and not only Children
  5. Still, if you do all the previous steps, and the info finally arrives into template_preprocess_layout(&$variables), the structure is not OK compared to a "regular" layout so it won't produce valid {{ region_attributes }}.

    Mainly, a regular layout features a nested ['content']['content'] render array, with the first ['content']['#attributes'] holding the '.layout-builder__layout' class and the nested ['content]['content']['#attributes'] the needed "layout-builder__region" and "js-layout-builder-region" classes, while a pattern will only feature a single ['content']. This is where I got stuck
Feature request
Status

Fixed

Component

User interface

Created by

🇪🇸Spain idiaz.roncero Madrid

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

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024