Issues with nested layout_paragraphs builders /reorder endpoint

Created on 13 November 2023, about 1 year ago

Problem/Motivation

My setup looks like this:

Node has a layout_paragraphs field which serves as the main content field.
Authors can add paragraphs using the "experimental" LP field widget.
There are paragraphs that render drupal blocks and
There are blocks that contain their own layout_paragraphs field with the same setup as the node above.

The logic is to allow the use of the same UI to create reusable blocks that can be used in content throughout the site.

So, to recap, Node -> paragraphs -> blocks -> paragraphs

With this setup when trying to reoder paragraphs within the blocks I face an issue where the AJAX request

/layout-paragraphs-builder/{$parent_builder_uuid}/reorder?_wrapper_format=drupal_ajax

... uses the ID of the outer layout_paragraphs builder, the one that belongs to the node which results in a 404 with the following message:

'The "layout_paragraphs_layout" parameter was not converted for the path "/layout-paragraphs-builder/{layout_paragraphs_layout}/reorder" (route name: "layout_paragraphs.builder.reorder")'

Steps to reproduce

Mimic the setup above and try to reorder paragraphs in your block using the front-end tool.

Proposed resolution

I traced this down to Drupal.behaviors.layoutParagraphsBuilder and specifically this

$(once('lpb-events', '[data-lpb-id]')).on(events, function (e) {
        var $element = $(e.currentTarget);
        updateUi($element);
      });

It seems that e.currentTarget is always the outer layout_builder whereas e.target is the builder that was clicked, as such I switched to:

      $(once('lpb-events', '[data-lpb-id]')).on(events, function (e) {
        var $element = $(e.target);
        updateUi($element);
      });

... and reordering now seems to be working as expected.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇷Greece magtak

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

Comments & Activities

Production build 0.71.5 2024