class BlockComponentRenderArraySubscriber in Layout Builder Blocks 1.0.x
Class BlockComponentRenderArraySubscriber.
Hierarchy
- class \Drupal\layout_builder_blocks\EventSubscriber\BlockComponentRenderArraySubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of BlockComponentRenderArraySubscriber
1 string reference to 'BlockComponentRenderArraySubscriber'
1 service uses BlockComponentRenderArraySubscriber
File
- src/
EventSubscriber/ BlockComponentRenderArraySubscriber.php, line 15
Namespace
Drupal\layout_builder_blocks\EventSubscriberView source
class BlockComponentRenderArraySubscriber implements EventSubscriberInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Drupal\Core\Config\ConfigFactoryInterface definition.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* BlockComponentRenderArraySubscriber constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Access configuration.
* @param \Drupal\bootstrap_styles\StylesGroup\StylesGroupManager $styles_group_manager
* The styles group plugin manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, ConfigFactoryInterface $config_factory, StylesGroupManager $styles_group_manager) {
$this->entityTypeManager = $entityTypeManager;
$this->configFactory = $config_factory;
$this->stylesGroupManager = $styles_group_manager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = [
'onBuildRender',
50,
];
return $events;
}
/**
* Add each component's block styles to the render array.
*
* @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event
* The section component render event.
*/
public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
$build = $event
->getBuild();
$block_style_configs = [];
if ($bootstrap_styles = $event
->getComponent()
->get('bootstrap_styles')) {
if (isset($bootstrap_styles['block_style'])) {
$block_style_configs = $bootstrap_styles['block_style'];
}
}
// Build dynamic styles.
if (count($block_style_configs) > 0) {
$build = $this->stylesGroupManager
->buildStyles($build, $block_style_configs, NULL);
}
$event
->setBuild($build);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockComponentRenderArraySubscriber:: |
protected | property | Drupal\Core\Config\ConfigFactoryInterface definition. | |
BlockComponentRenderArraySubscriber:: |
protected | property | The entity type manager. | |
BlockComponentRenderArraySubscriber:: |
public static | function | ||
BlockComponentRenderArraySubscriber:: |
public | function | Add each component's block styles to the render array. | |
BlockComponentRenderArraySubscriber:: |
public | function | BlockComponentRenderArraySubscriber constructor. |