Layouts are just plugins that by default use \Drupal\Core\Layout\LayoutDefault
as its implementation. The built-in two-column and three-column layouts extend from MultiWidthLayoutBase
which extends from LayoutDefault
. Their implementation is custom, allowing them to define that width distribution select whenever you use them.
You can use this same approach to add custom configuration to your layout, and allow a site-builder to customize it whenever they use it (like adding an input that accepts classes for a specific region). To do this, you'll need to do the following:
- Define a class extending
LayoutDefault
.
- Define your layout in
.layouts.yml
, with its class
pointing your class in Step 1.
- In this custom class, define the additional configuration properties and their form inputs for whatever you want configurable (e.g. add a textfield for adding classes for a specific region)
- In the layout's twig, find and consume that property to customize the region (e.g. print the class)
- Repeat 3 and 4 for other things you want configurable in the layout.
See https://www.drupal.org/docs/drupal-apis/layout-api/how-to-register-layouts#using-class-key for details on how to define a layout with custom configuration.