Paragraphs lost when switching layout with custom layout configuration settings

Created on 18 July 2023, 12 months ago
Updated 22 February 2024, 4 months ago

Problem/Motivation

When switching a layout to another one with different regions, all paragraphs from the former regions, which don't exist in the changed layout, are lost (no more visible!)

This seems to happen in combination with custom layout setting that differ from layout to layout.
Maybe the validation is breaking things here. I'll investigate further and POSTPONE the issue for further information.
In our case, it happens when switching between these layouts: https://git.drupalcode.org/project/drowl_layouts/-/tree/4.x/src/Plugin/L...

Steps to reproduce

Add a layout paragraph with 3 colums for example (col1,col2,col3)
Add paragraphs to the layout
Edit the layout paragraph and swich to 1 column layout (col1). The paragraphs from col2 and col3 are gone.

Proposed resolution

When changing layouts, compare the available regions and either
a) ask the user where to move the paragraphs from the missing regions
b) just move them into the first region instead

In the long run, it should be (a) but to fix it asap, (b) is fine!

Workaround:
Insted of changing layouts, create the new layout below and move the paragraphs over.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

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

Comments & Activities

  • Issue created by @Anybody
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    This is going to be updated. The issue is more specific and only seems to happen in combination with custom layout setting that differ from layout to layout.
    Maybe the validation is breaking things here. I'll investigate further and POSTPONE the issue for further information.
    In our case, it happens when switching between these layouts: https://git.drupalcode.org/project/drowl_layouts/-/tree/4.x/src/Plugin/L...

  • Status changed to Postponed: needs info 12 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • a) ask the user where to move the paragraphs from the missing regions

    This already happens for regular layouts!

    The problem occurs, if they are layout setting-values available in the origin layout, which are not available in the new layout.

    See this, step by step:

  • Assigned to Anybody
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡ΊπŸ‡ΈUnited States joegl

    I believe we are running into the same thing here: https://www.drupal.org/project/layout_paragraphs/issues/3393704#comment-... πŸ’¬ Form error on layout section when using module layout_section_classes Active

    I thought the bug/error in the above issue was harmless but it turns out it's causing the problem described in this issue.

    Going to link these two issues.

    Does anyone have a good solution for this? We need to be able to have separate options available in different layouts and we can't always force the keys to match.

  • Status changed to Active 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States joegl
  • Issue was unassigned.
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡ΊπŸ‡ΈUnited States joegl

    I'm going to re-summarize the issue here for my own clarity (apologies for any redundancy).

    We extend the core `layout_builder``MultiWidthLayoutBase` class which adds width options to the configuration form (Layout Options in the Layout Paragraphs) using the `getWidthOptions()` method. When two layouts have different Width Options and we switch between them, there is an error "The submitted value (VALUE_HERE) in the Content Width element is not allowed." If there is existing paragraphs, the error does not effect anything. If there are existing paragraphs. some of them are lost.

    I've been having trouble debugging the validateConfigurationForm method, but from what I can tell, the newly selected layout options are being used to validate against the selected form value for the option.

    E.g., If you have a one column layout selected with '100' => '100%' as the width options and then switch to a two column layout with '50-50' => '50% - 50%' as the width options, it's going to validate your selected option in the form for the one column (100) against the options for the two column layout (50-50).

  • πŸ‡ΊπŸ‡ΈUnited States joegl

    A really inelegant workaround I've found is to set the field as already validated in the buildConfigurationForm() method of our base class:

     public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    
        // at bottom of the method
        $form = parent::buildConfigurationForm($form, $form_state);
        $form['column_widths']['#validated'] = TRUE;
        return $form;
      }
    

    Ideally none of the fields in the $form['config'] in layout_paragraphs/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php would not be validated when a new layout selection is made in the , and only validated once the layout selection is saved.

Production build 0.69.0 2024