Problem/Motivation

I want to be able to nest sections, but i cannot add a section in another section. Even using experimental widget and settings max nested value.

Steps to reproduce

I have a section paragraph configured as section layout paragraph and multiple layout paragraphs (which can also have sections and layouts, but this part works).
I configure thanks to layout_builder an article content type with paragraph field with experimental layout paragraph widget.
The widget is configured to allow maximum of 10 nesting elements.
I can add a first section, but i cannot add a nested section

Proposed resolution

Digging on module, i try :

  • Hard code default settings in LayoutParagraphLayouts constructor to add nesting_depth to 10 by default
  • Hard code default widget settings to add nesting_depth to 10 by default

None of those work.

Looking at \Drupal\layout_paragraphs\Form\LayoutParagraphsBuilderForm::buildForm()

      $render_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
      $renderer = $render_display->getRenderer($field_name);
      $layout_paragraphs_settings = $renderer->getSettings() + ['reference_field_view_mode' => $view_mode];

call \Drupal\Core\Entity\Entity\EntityViewDisplay::getRenderer()

    // Instantiate the formatter object from the stored display properties.
    if (($configuration = $this->getComponent($field_name)) && isset($configuration['type']) && ($definition = $this->getFieldDefinition($field_name))) {

Except at this point, $configuration is setted with default settings including nesting_depth = 0.

{
  "view_mode": "default",
  "link": "",
  "preview_view_mode": "default",
  "form_display_mode": "default",
  "nesting_depth": 0,
  "require_layouts": 0,
  "empty_message": ""
}

Don't know why, but layout settings is initiate with default values i cannot configure.

The fact is when i load the choose component widget for a nested section (so in paragraph field of paragraph section), we don't know the form display (the paragraph field of parent node), and so the widget settings.

Comments

goz created an issue. See original summary.

goz’s picture

Title: Cannot nest sections » Cannot nest sections from display

If i use the edit form, everything works fine.
Issue is only when i want to edit sections from the node display

goz’s picture

Title: Cannot nest sections from display » Cannot nest sections from display configured with layour builder

I confirm this work without using layout builder to build my node page

goz’s picture

i find a workaround :

  1. Configure default node display without layout builder and set widget with nesting_depth to 10.
  2. Add full content view mode and configure it with layout builder.

Now, i can add nested sections. When i want to add the nested section, i guess it can find the settings from the no-layout builder default view mode

goz’s picture

FYI, when layout builder was configured on default view mode, i had to add the first section from the edit form, because paragraph layout edition link was not displaying.
There is definitively an issue when layout builder is configured on default view mode

tiago’s picture

Related: #3627004

I think this will solve your problem. The cause is that Layout Builder renders fields through FieldBlock::build(), so the formatter receives _custom as its view mode. The builder URL ends in _custom, collectRenderDisplay() falls back to the default display, and nesting_depth and require_layouts are not found.

I opened a separate issue because the same cause also makes Close empty the field and lets the route accept any view mode, and the fix targets 3.0.x while this one is filed against 2.1.x. MR !273 fixes all three issues. The same diff applies cleanly to 2.1.x if you need it there.

If you want to try it, there is a patch in the third comment of the related issue.