Problem/Motivation
I tried creating a custom Style plugin but it's not working because the build() method is never called. This is happening both using layouts (bootstrap_layout_builder) and blocks (layout_builder_blocks).
I've managed to trace it down to when Drupal\bootstrap_styles\StylesGroup::buildStyles
is called:
public function buildStyles(array $build, array $plugins_storage, $theme_wrapper = NULL) {
I can see that $plugins_storage
is never listing my custom plugin, so it won't be instantiated and therefore its build() method won't be called.
$plugins_storage
comes from Drupal\bootstrap_layout_builder\Plugin\Layout\BootstrapLayout::build()
, exactly from $this->configuration['container_wrapper']['bootstrap_styles']
. This configuration is not taking into consideration the new plugin.
// Build dynamic styles.
$build = $this->stylesGroupManager->buildStyles(
$build,
// storage.
$this->configuration['container_wrapper']['bootstrap_styles'],
// Theme wrapper that we need to apply styles to it.
'blb_container_wrapper'
);
Tests and additional info:
-> Caches have been cleared
-> I have tested both on already existing layouts/blocks and creating brand new layouts/blocks.
-> My custom plugin is a copy of TextAlignment
plugin, just changing the machine names.
-> The rest of the plugin works as expected: values can be introduced and saved, it's listed on the config pages, can be enabled and disabled, forms appear and its data is saved.
Steps to reproduce
Create a Custom Style plugin, in this case a copy of \Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style\TextAlignment
, on a custom module.
Enable the module, enable the plugin on (for layouts) '/admin/config/bootstrap-layout-builder/styles' or (for blocks) '/admin/config/layout-builder-blocks/styles'.
Configure the new plugin classes on '/admin/config/bootstrap-styles/settings'. Save them.
Use the style on a layout section or block using one of the modules that implement bootstrap_styles (layout_builder_blocks or bootstrap_layout_builder).
The value will be saved but the class won't be added to the block/section as the build() method is never called.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes