Regions loose attributes

Created on 5 February 2025, 2 months ago

Problem/Motivation

Using layout_paragraphs and mercury editor, i found out that #attributes passed to regions do not display. In this case, we cannot use bootstrap grid layouts because some required classes are missing.

Here is the context of component_id ui_suite_bootstrap:grid_row_2

{
  "attributes": [],
  "container_attributes": [],
  "container_wrapper_attributes": [],
  "col_xs": [
    "",
    ""
  ],
  "col_sm": [
    "",
    ""
  ],
  "col_md": [
    "",
    ""
  ],
  "col_lg": [
    "",
    ""
  ],
  "col_xl": [
    "",
    ""
  ],
  "col_xxl": [
    "",
    ""
  ],
  "col_offset": [
    "",
    ""
  ],
  "col_1_attributes": [],
  "col_2_attributes": [],
  "col_1_content": {
    "#attributes": {
      "class": [
        "js-lpb-region"
      ],
      "data-region": "col_1_content",
      "data-region-uuid": "29dce290-8b92-4a65-b474-411d340891a5-col_1_content",
      "data-lpb-ui-id": "29dce290-8b92-4a65-b474-411d340891a5-col_1_content",
      "data-has-js-ui-element": true
    },
    "#attached": {
      "drupalSettings": {
        "lpBuilder": {
          "uiElements": {
            "29dce290-8b92-4a65-b474-411d340891a5-col_1_content": {
              "insert": {
                "element": "\n\n<!-- THEME DEBUG -->\n<!-- THEME HOOK: 'layout_paragraphs_insert_component_btn' -->\n<!-- BEGIN OUTPUT from 'modules\/contrib\/layout_paragraphs\/templates\/layout-paragraphs-insert-component-btn.html.twig' -->\n<a class=\"lpb-btn--add use-ajax center\" data-dialog-type=\"dialog\" data-dialog-options=\"{&quot;target&quot;:&quot;lpb-dialog-25cdfce06bafb980a112bee55d295399&quot;,&quot;width&quot;:&quot;fit-content&quot;,&quot;height&quot;:&quot;fit-content&quot;,&quot;drupalAutoButtons&quot;:false,&quot;dialogClass&quot;:&quot;lpb-dialog&quot;,&quot;resizable&quot;:true}\" href=\"\/mercury-editor\/25cdfce06bafb980a112bee55d295399\/choose-component?parent_uuid=29dce290-8b92-4a65-b474-411d340891a5&amp;region=col_1_content&amp;me_id=bbec6e2f-62e6-4f32-ac24-1352e9c64cf7\"><span class=\"visually-hidden\">Choose component<\/span><\/a>\n\n<!-- END OUTPUT from 'modules\/contrib\/layout_paragraphs\/templates\/layout-paragraphs-insert-component-btn.html.twig' -->\n\n",
                "method": "append"
              }
            }
          }
        }
      }
    }
  },
  "col_2_content": {
    "#attributes": {
      "class": [
        "js-lpb-region"
      ],
      "data-region": "col_2_content",
      "data-region-uuid": "29dce290-8b92-4a65-b474-411d340891a5-col_2_content",
      "data-lpb-ui-id": "29dce290-8b92-4a65-b474-411d340891a5-col_2_content",
      "data-has-js-ui-element": true
    },
    "#attached": {
      "drupalSettings": {
        "lpBuilder": {
          "uiElements": {
            "29dce290-8b92-4a65-b474-411d340891a5-col_2_content": {
              "insert": {
                "element": "\n\n<!-- THEME DEBUG -->\n<!-- THEME HOOK: 'layout_paragraphs_insert_component_btn' -->\n<!-- BEGIN OUTPUT from 'modules\/contrib\/layout_paragraphs\/templates\/layout-paragraphs-insert-component-btn.html.twig' -->\n<a class=\"lpb-btn--add use-ajax center\" data-dialog-type=\"dialog\" data-dialog-options=\"{&quot;target&quot;:&quot;lpb-dialog-25cdfce06bafb980a112bee55d295399&quot;,&quot;width&quot;:&quot;fit-content&quot;,&quot;height&quot;:&quot;fit-content&quot;,&quot;drupalAutoButtons&quot;:false,&quot;dialogClass&quot;:&quot;lpb-dialog&quot;,&quot;resizable&quot;:true}\" href=\"\/mercury-editor\/25cdfce06bafb980a112bee55d295399\/choose-component?parent_uuid=29dce290-8b92-4a65-b474-411d340891a5&amp;region=col_2_content&amp;me_id=bbec6e2f-62e6-4f32-ac24-1352e9c64cf7\"><span class=\"visually-hidden\">Choose component<\/span><\/a>\n\n<!-- END OUTPUT from 'modules\/contrib\/layout_paragraphs\/templates\/layout-paragraphs-insert-component-btn.html.twig' -->\n\n",
                "method": "append"
              }
            }
          }
        }
      }
    }
  }
}

We can see there is no col_1_attributes and there is #attributes in col_1_content.

How to move col_1_content#attributes to col_1_attributes ?

Here is a solution in grid_row_2.twig

{% set col_attributes = [
  create_attribute(col_1_attributes|default({})|merge(col_1_content['#attributes']|default({}))),
  create_attribute(col_2_attributes|default({})|merge(col_2_content['#attributes']|default({}))),
] %}

But i guess there is a better solution where #attributes could be passed to attributes props instead of doing this in twig, so it can works in any cases.
Maybe a relation with 📌 [2.0.0-rc2] ContextException with entity:paragraph Active

🐛 Bug report
Status

Active

Version

5.1

Component

Code

Created by

🇫🇷France goz

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

Comments & Activities

Production build 0.71.5 2024