class SectionComponentBuildRenderArrayEvent

Same name in other branches
  1. 8.9.x core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent
  2. 10 core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent
  3. 11.x core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent

Event fired when a section component's render array is being built.

Subscribers to this event should manipulate the cacheability object and the build array in this event.

Hierarchy

Expanded class hierarchy of SectionComponentBuildRenderArrayEvent

See also

\Drupal\layout_builder\LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY

4 files declare their use of SectionComponentBuildRenderArrayEvent
BlockComponentRenderArray.php in core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php
BlockComponentRenderArrayTest.php in core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php
SectionComponent.php in core/modules/layout_builder/src/SectionComponent.php
SectionComponentTest.php in core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php

File

core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php, line 18

Namespace

Drupal\layout_builder\Event
View source
class SectionComponentBuildRenderArrayEvent extends Event {
    use CacheableResponseTrait;
    
    /**
     * The section component whose render array is being built.
     *
     * @var \Drupal\layout_builder\SectionComponent
     */
    protected $component;
    
    /**
     * The available contexts.
     *
     * @var \Drupal\Core\Plugin\Context\ContextInterface[]
     */
    protected $contexts;
    
    /**
     * The plugin for the section component being built.
     *
     * @var \Drupal\Component\Plugin\PluginInspectionInterface
     */
    protected $plugin;
    
    /**
     * Whether the component is in preview mode or not.
     *
     * @var bool
     */
    protected $inPreview;
    
    /**
     * The render array built by the event subscribers.
     *
     * @var array
     */
    protected $build = [];
    
    /**
     * Creates a new SectionComponentBuildRenderArrayEvent object.
     *
     * @param \Drupal\layout_builder\SectionComponent $component
     *   The section component whose render array is being built.
     * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
     *   The available contexts.
     * @param bool $in_preview
     *   (optional) Whether the component is in preview mode or not.
     */
    public function __construct(SectionComponent $component, array $contexts, $in_preview = FALSE) {
        $this->component = $component;
        $this->contexts = $contexts;
        $this->plugin = $component->getPlugin($contexts);
        $this->inPreview = $in_preview;
        if ($this->plugin instanceof PreviewAwarePluginInterface) {
            $this->plugin
                ->setInPreview($in_preview);
        }
    }
    
    /**
     * Get the section component whose render array is being built.
     *
     * @return \Drupal\layout_builder\SectionComponent
     *   The section component whose render array is being built.
     */
    public function getComponent() {
        return $this->component;
    }
    
    /**
     * Get the available contexts.
     *
     * @return array|\Drupal\Core\Plugin\Context\ContextInterface[]
     *   The available contexts.
     */
    public function getContexts() {
        return $this->contexts;
    }
    
    /**
     * Get the plugin for the section component being built.
     *
     * @return \Drupal\Component\Plugin\PluginInspectionInterface
     *   The plugin for the section component being built.
     */
    public function getPlugin() {
        return $this->plugin;
    }
    
    /**
     * Determine if the component is in preview mode.
     *
     * @return bool
     *   Whether the component is in preview mode or not.
     */
    public function inPreview() {
        return $this->inPreview;
    }
    
    /**
     * Get the render array in its current state.
     *
     * @return array
     *   The render array built by the event subscribers.
     */
    public function getBuild() {
        return $this->build;
    }
    
    /**
     * Set the render array.
     *
     * @param array $build
     *   A render array.
     */
    public function setBuild(array $build) {
        $this->build = $build;
    }

}

Members

Title Sort descending Modifiers Object type Summary
CacheableResponseTrait::$cacheabilityMetadata protected property The cacheability metadata.
CacheableResponseTrait::addCacheableDependency public function
CacheableResponseTrait::getCacheableMetadata public function
SectionComponentBuildRenderArrayEvent::$build protected property The render array built by the event subscribers.
SectionComponentBuildRenderArrayEvent::$component protected property The section component whose render array is being built.
SectionComponentBuildRenderArrayEvent::$contexts protected property The available contexts.
SectionComponentBuildRenderArrayEvent::$inPreview protected property Whether the component is in preview mode or not.
SectionComponentBuildRenderArrayEvent::$plugin protected property The plugin for the section component being built.
SectionComponentBuildRenderArrayEvent::getBuild public function Get the render array in its current state.
SectionComponentBuildRenderArrayEvent::getComponent public function Get the section component whose render array is being built.
SectionComponentBuildRenderArrayEvent::getContexts public function Get the available contexts.
SectionComponentBuildRenderArrayEvent::getPlugin public function Get the plugin for the section component being built.
SectionComponentBuildRenderArrayEvent::inPreview public function Determine if the component is in preview mode.
SectionComponentBuildRenderArrayEvent::setBuild public function Set the render array.
SectionComponentBuildRenderArrayEvent::__construct public function Creates a new SectionComponentBuildRenderArrayEvent object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.