Allow to drag and drop nested paragraphs

Created on 13 November 2023, about 1 year ago

Steps to reproduce

Create nested paragraphs: for example accordion and accordion item. User should be allowed to add accordion item inside accordion.
Configure layout paragraph, allow to add accordion paragraph.
Use Paragraphs (stable) widget to display accordion items (default widget).

Visit node where layout paragraph is configured
Add accordion paragraph with a few accordion items

Click on "Drag & drop" link in the right corner Move some items, click on "Complete drag & drop"

System generates the following error:
Error: Call to undefined method Drupal\layout_paragraphs\Form\EditComponentForm::getEntity() in Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget::reorderParagraphs() (line 2116 of /app/web/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php).

Proposed resolution

ParagraphsWidget expects that getFormObjecjt is a EntityForm and has getEntity() method
rename getParagraph to getEntity() in ComponentFormInterface

This can break some customisation but i do not see any other way.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇵🇱Poland alorenc Wolsztyn, 🇵🇱

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

Comments & Activities

  • Issue created by @alorenc
  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    55 pass
  • @alorenc opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱
  • Status changed to RTBC about 1 year ago
  • 🇬🇷Greece idimopoulos

    A but more precise with this:
    I am defining 3 paragraphs. 1 for a single layout, 1 for the accordion, 1 for the accordion item.
    Then I have in the entity a paragraphs revision for the paragraphs which is using layout builder.
    Then I have the 1 column layout use the stable paragraphs.
    And that is how it is indeed the problem is reproduced. The patch fixes the issue. +1 RTBC. Tested in vanilla Drupal

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States justin2pin

    Thanks for the MR - it sounds like this will work for users running into this specific issue, and passes tests.

    I think we should probably think through this issue a little more though and consider changing LP form classes to use the EntityForm interface. Obviously this would change the API, so needs a little more consideration. Perhaps we can implement EntityFormInterface ComponentFormInterface for backwards compatibility.

    Marking as needs work so we can continue to work on the issue.

  • 🇮🇳India SohiniCP

    The provided MR only resolves the Ajax error, but the nested paragraph issue still persists. I'm using version 2.1.0. Now, each paragraph is being treated as a new 'ajax-new-content'. I've attached a screenshot: , which shows the issue when using 'Layout Paragraph' as a widget. Additionally, I’ve attached a video: Paragraph Drag Drop issue , demonstrating the problem when using only the 'Paragraphs (stable)' widget.

    Instead of loading in a single container, each paragraph is split into its own container, and we are unable to drag and drop the paragraphs.

Production build 0.71.5 2024