- 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
over 1 year ago 7:42am 18 July 2023 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
- πΊπΈ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
10 months ago 6:01pm 22 February 2024 - Issue was unassigned.
- πΊπΈ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']
inlayout_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. - π©πͺGermany berliner
I have also run into the same issue as @joegl. My work-around looks like this:
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); $input = $form_state->getUserInput(); $element_parents = ['layout_paragraphs', 'config', 'column_widths']; $columns_width = NestedArray::getValue($input, $element_parents); if (!array_key_exists($columns_width, $this->getWidthOptions())) { NestedArray::setValue($input, $element_parents, $this->getDefaultWidth()); $form_state->setUserInput($input); } return $form; }