Site Building

Dynamic Layout Plugins in Drupal's Layout Builder for Drupal 8, 9, and 10

In their simplest form layout plugins in Drupal Layout Builder define the part of the content output that can't be changed. For example a three column layout will consist of three equal columns every time an editor decides to use it as the layout section. The editor can place whatever they want into the three columns. But they can not change the overall layout. This restricts editorial capabilities of using layout plugins since in real life a three column layout may need to consist of a wider middle column and narrower side columns, allow for column headings, or other customizations.

This flexibility is accomplished by creating, and exposing, configuration options for layout plugins in Drupal's Layout Builder. In more advanced cases, the we can take this flexibility further by exposing an interface editors to dynamically define layout plugins.

In this tutorial we'll:

  • Learn how to use custom PHP classes in the layout plugin annotation
  • Learn what annotations properties can be used for custom layout declaration
  • Define the concept of derivatives and outline scenarios for using them
  • How to declare static single layouts using YAML format

By the end of this tutorial you'll learn advanced ways of declaring configurable custom layout plugins.