Problem/Motivation

For many page layouts, section layouts often need to nested to achieve the required layout designs. Right now layout builder doesn't make this easy because layout sections cannot be nested. This requires developers and site builders to incorporate some other way to added these nested grids, such as a grid paragraph type, or using the standard block UI for adding sidebar blocks.

For instance, one common page layout is having a left and right sidebar section and middle content section. The left sidebar section might have a menu block, while the right might have related block such as related content/links, forms, ads, or other information complementary to the main content. Within the middle content section, content editors often still need to place content in multi-column grids. Some examples include: placing an image and text in a 2 column grid (often called a media object), a grid of cards or photos, multi-column lists, etc.

Allowing layout builder sections to be nested would greatly increase the flexibility and functionality to easily implement even the most complex of layouts.

Proposed resolution

Extend layout builder sections functionality to allow them to nested.

Remaining tasks

Agree on an approach and implement.

User interface changes

Layout builder UI will be to be adjusted to properly accommodate nested sections.

API changes

Unknown.

Data model changes

Unknown.

Comments

PCate created an issue. See original summary.

andrewmacpherson’s picture

All of the accessibility work done so far has been on the assumption that there is a linear sequence of sections. All the indications I heard from the layout initiative team were that nested sections weren't part of the plan. Adding nested sections will complicate accessibility, to the extent that all bets are off for the accessibility plan so far.

adrian83’s picture

Just passing along two workarounds available to the site-builder or themer now:

  1. This one will not solve all use-cases, but, if placing custom or one-time-use inline blocks (or paragraphs), they can also be laid out with layout builder. So, a block laid out in two columns could be placed in my node within one of 2 columns. However, the two layouts would be happening at different routes, I believe.
  2. Even though one of Layout Builder's great features is the ability to build a complex layout by stacking simple layout sections, the site-builder or themer could write a more complex layout to be used within layout builder.
tedbow’s picture

I agree with @andrewmacpherson that this could cause accessibility problems. I think we should continue to improve the accessibility of current functionality before adding features that will make it more complicated.

The examples in the issue summary to don't seem like they need nested sections

placing an image and text in a 2 column grid (often called a media object)

This should just really use the media module. Then you could use the Layout Builder on the media display.

a grid of cards or photos

This could either be a View in a grid or a custom block that has references to media entities(that you could add directly when the media library is stable). You could use different view modes on the block type to allow different arrangement of the media entities on the block display.

coderbrandon’s picture

Example use case I've run into: At the high level the page needed to support 2 columns: sidebar and main content. But, the content inside the main content "side" of the 2 column section needed to be able to be laid out with multicolumn subsections. I can't just define a custom layout b/c the main content side needs to be able to be customized and I don't want to lock the editor into a specific grid or masonry layout and I don't want to force them out of the Layout Builder UI to create something with a different contrib module. The current workaround is that we created a custom "sidebar" one column section layout but will be using CSS to force it to render to the side the rest of the sections under it.

For accessibility, it would be good to know the specifics for which pieces don't currently support a nested approach.

mikeohara’s picture

My envisionment of this would be similar to D7's Mini panels. Whereby you can create reusable pieces that can be placed into layouts and receive context from the layout driven entity.

adrian83’s picture

Interestingly, here is a contrib module posted two days ago: https://www.drupal.org/project/mini_layouts

euclid.h’s picture

StatusFileSize
new69.3 KB

I think using module like Paragraph blocks: https://www.drupal.org/project/paragraph_blocks for using the Layout

Sections: each section can contain content arranged in a certain layout.
Example: 2 columns, 3 columns, etc.

Inside each section, you can display:
Fields from the content being displayed. Example: title, body, tags, etc.
Blocks which appear on the Structure > Block Layout page.Example:Page title, tabs, blocks from the custom block library, etc.

Here's more explanation: https://www.youtube.com/watch?v=73uepd9CLFI&feature=youtu.be

rlmumford’s picture

The mini_layouts project would solve this use case:

https://www.drupal.org/project/mini_layouts

mikeohara’s picture

@rlmumford this is awesome I'm going to check it out.

luke_nuke’s picture

Actually, it might be surprisingly easy to do already.

I think we can define layout regions dynamically in the custom Layout's constructor, based off the Layout configuration, by modifying $plugin_definition. It seems to work. That way we can just plainly configure new layout regions and structures in our layout configuration. Sky is the limit. :)

I'm still playing with it, but it seems to work.

luke_nuke’s picture

#3075939: Allow layouts to provide dynamic regions Guys, what do you think about this approach? It's much less invasive, and contrib modules could easily implement configurable sublayouts/subsections which would be simply a part of section's configuration.

zviryatko’s picture

StatusFileSize
new637.08 KB
new104.85 KB

Hello, I've started to implement nested layout on the project, right now the work still in progress and as a limitation, it supports only one level of nesting (but honestly that's enough) otherwise it requires huge refactoring of layouts module.

Implementation

In the core, we have two base models: Block and Layout.
Layouts contain blocks inside, it stores their Uuid, order, and configurations.
Block presents some real content, it can be entity, field or anything defined as Drupal's block.
In my implementation, I've added a new block type called LayoutBlock which supports both Layouts and Block inside. Improved default routes to support Block Uuid of source and destination blocks. Extended standard controllers and rendering and added an additional check for LayoutBlock and iterating through all children.

I'll try to move it to contrib module when I finish, right now I can share only screenshots.

rlmumford’s picture

@zviryatko that sounds exactly like the mini_layouts module.

zviryatko’s picture

@rlmumford, yes, implementation similar, but I want to achieve the possibility to moving components between different nested layouts on the same page, to make it easy and avoid opening many pages when you just need simple move block from one sub-section to another. Does mini_layouts allow to do it like in screenshot that I provided?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

rgnyldz’s picture

Wow, this would be really nice to have. Any update on this issue?

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

geek-merlin’s picture

In fact it's much simpler and does not require new concepts:
1) ☑ Create a lb_block block type that is, well, LB enabled
2) ☑ Place a block of that type in any LB layout
3a) ☑ If it's a reusable block, we can edit it's layout on a separate page and are done
3b) ⚠️ If it's an inline block, we want to edit it's layout (probably on a separate page via target=_blank, as we die in panels for views for ages)

So it boils down to: Provide a link to edit an inline block's layout.

eugen zerr’s picture

Hello everyone, :)

I'm currently working on this topic and would like to share with you my progress.
First off geek-merlin comment in #19 helped me alot.
But I wasn't pleased with the idea of "edit it's layout on a separate page" which is simply outdated and shouldn't be used in any way in 2020.
This should also be possible in the same block (in my case block content).

So my idea was (My code depends on "Block Content" entities but it also should be able to support other entities):

Please do remember, that this is code to prove that my idea actually works.
1. Do the tasks from 1) to 3a) from #19
2. Create a hook which preprocesses the element (in my case an inline block).


/**
 * @file
 * Contains hook.module.
 */

function hook_preprocess_block__inline_block__myaccordion(array &$variables) {
  $routeMatch = \Drupal::routeMatch();

  // \Drupal\layout_builder\Controller\LayoutBuilderController::layout
  $allowed_routes = [
    'layout_builder.move_block',
    'layout_builder.overrides.node.view',
  ];

  // Check if we are on the right route.
  if (!in_array($routeMatch->getRouteName(), $allowed_routes)) {
    return;
  }

  /** @var \Drupal\block_content\Entity\BlockContent $block_content */
  $block_content = \Drupal::entityTypeManager()->getStorage('block_content')->loadRevision($variables['configuration']['block_revision_id']);
  
  // Load the controller which handles the render.
  $layout_view = new \Drupal\layout_builder\Controller\LayoutBuilderController();

  // Get context.
  $entityContext = \Drupal\Core\Plugin\Context\EntityContext::fromEntity($block_content);

  /** @var \Drupal\layout_builder\SectionStorage\SectionStorageManager $sectionStorageManager */
  $sectionStorageManager = \Drupal::service('plugin.manager.layout_builder.section_storage');

  // Load the corresponding section storage.
  $sectionStorage = $sectionStorageManager->load('overrides', ['entity' => $entityContext]);

  // Render and override the elements.
  $variables['content'] = $layout_view->layout($sectionStorage);
}

3. Apply the patch 3053145-layout-builder-in-layout-builder.patch. It updates the layout builder html id attribute, so the right element gets replaced when adding new sections, blocks etc..

Until this point almost everything looks as expected and works really good.
The problem I face currently is that the initial loading of the nested element is empty (Provided by the hook).
But editing the nested element somehow updates the nested element with the previous edited stuff.
It would be really cool if someone who created or helped to create layout builder could explain how this one works.

Worth mentioning is that I commented out drupal/core/lib/Drupal/Core/Routing/AccessAwareRouter.php Line 115 - 122
as it throws an excess denied, even when I'm Super Admin.

Problems to solve before this can be used.

1. Initial loading of the nested element.
2. Access » Somehow I get access denied as Super Admin.
3. Submission of the nested element.

Greeting,
Eugene :)

eugen zerr’s picture

Priority: Normal » Major
donquixote’s picture

A cheap and easy solution would be to allow nesting of view modes with layout builder.

Here is what we would need:

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

nwom’s picture

I'm really looking forward to using this (even as a patch). Any luck on getting the open issues fixed?:

1. Initial loading of the nested element.
2. Access » Somehow I get access denied as Super Admin.
3. Submission of the nested element.
geek-merlin’s picture

@Eugen Zerr #20: Cool that i could inspire you!
TBH i did not fully realize your workaround.

But here is what i thought when i looked into the source code last time:
- What we need is a "edit layout" contextual action
- What we do have is a "edit" contextual action

So we can look into how the "edit" contextual link and action is implemented. It combines
- editing the inline block
- updating the revision reference in the layout (because a layout always has to ref the latest revision, otherwise it coughs)

So what we have to do is, imitate everything that is done in "edit", and imitate it in "edit layout".
Feel free to PM me if you want to work on it and need more pointers.

eit2103’s picture

I think the mini layouts module does the job.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcraig91’s picture

StatusFileSize
new191.4 KB

What you need is the module LayoutComponents

This is an example of what you are able to do: lc-subsections

In this example you can see a parent section with 2 colums, in the first region are included 2 more sections with their regions and 1 more in the second region of parent section. Ofcourse without needs to generate any twig or modification by code because the module generate the structures dinamically dependly the configuration seted in each section.

pd: The sub section functionallity are under development but will be available very soon.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

indymeermans’s picture

Almost 2 years further, is there by chance any update on this? Any way to fix this instead using another module like layoutcomponents?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mgifford’s picture

Issue tags: +wcag243

Tagging for https://www.w3.org/WAI/WCAG20/Understanding/focus-order which is the most likely error which would be introduced by this feature.

murz’s picture

Seems both the most promising modules:
- https://www.drupal.org/project/mini_layouts
- https://www.drupal.org/project/layoutcomponents
got abandoned, I see no new commits during the last 2 years and no support for Drupal 11.x

Maybe some alternatives appeared to allow inserting sections into sections or somehow group blocks in the region of the Layout Builder Section? For example, simply group two fields to display as one line, like this:

<div class="group--full-title">
  <div class="field--title">My title</div>
  <div class="field--title-suffix">with suffix</div>
</div>
emircan erkul’s picture

Priority: Major » Critical

As a Drupal 11 developer, i also face similar issue. And both suggested module do not supported. And don't want to deal with content blocks as some workarounds shows.

This is really fundumental basic thing when we think layout builder. But not sure why this not prioritized.. maybe whole layout builder get abandoned for sake of new experience builder thing..

murz’s picture

Seems this is not possible from the technical side because of the limitation of the initial architecture of the Layout Builder components. So, the Drupal community rethought this approach from scratch and re-implemented it as Drupal Canvas https://www.drupal.org/project/canvas

Therefore, seems all new efforts will be invested into developing Drupal Canvas, instead of improving the Layout Builder ;(

grimreaper’s picture

Hi,

Canvas is not the only alternative.

There is also https://www.drupal.org/project/display_builder, related to https://www.drupal.org/project/ui_suite.

Disclaimer: I am involved in Display Builder development and UI Suite core team.

PS: Hi @murz, hope you enjoy the apron from Trivia night ;)

anruether’s picture

Priority: Critical » Normal

@emircan erkul Please read the issue priority guidelines before escalating: https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-...

On rare occasions, Drupal core product managers may identify an especially important feature request as critical. In most cases, only core committers should mark a feature request as critical, and it is ultimately up to the product managers to determine which feature requests are critical.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.