3 namespace Drupal\layout_builder\Event;
5 use Drupal\Core\Cache\CacheableResponseTrait;
6 use Drupal\layout_builder\SectionComponent;
7 use Symfony\Component\EventDispatcher\Event;
10 * Event fired when a section component's render array is being built.
12 * Subscribers to this event should manipulate the cacheability object and the
13 * build array in this event.
15 * @see \Drupal\layout_builder\LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY
18 * Layout Builder is currently experimental and should only be leveraged by
19 * experimental modules and development releases of contributed modules.
20 * See https://www.drupal.org/core/experimental for more information.
22 class SectionComponentBuildRenderArrayEvent extends Event {
24 use CacheableResponseTrait;
27 * The section component whose render array is being built.
29 * @var \Drupal\layout_builder\SectionComponent
34 * The available contexts.
36 * @var \Drupal\Core\Plugin\Context\ContextInterface[]
41 * The plugin for the section component being built.
43 * @var \Drupal\Component\Plugin\PluginInspectionInterface
48 * Whether the component is in preview mode or not.
55 * The render array built by the event subscribers.
59 protected $build = [];
62 * Creates a new SectionComponentBuildRenderArrayEvent object.
64 * @param \Drupal\layout_builder\SectionComponent $component
65 * The section component whose render array is being built.
66 * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
67 * The available contexts.
68 * @param bool $in_preview
69 * (optional) Whether the component is in preview mode or not.
71 public function __construct(SectionComponent $component, array $contexts, $in_preview = FALSE) {
72 $this->component = $component;
73 $this->contexts = $contexts;
74 $this->plugin = $component->getPlugin($contexts);
75 $this->inPreview = $in_preview;
79 * Get the section component whose render array is being built.
81 * @return \Drupal\layout_builder\SectionComponent
82 * The section component whose render array is being built.
84 public function getComponent() {
85 return $this->component;
89 * Get the available contexts.
91 * @return array|\Drupal\Core\Plugin\Context\ContextInterface[]
92 * The available contexts.
94 public function getContexts() {
95 return $this->contexts;
99 * Get the plugin for the section component being built.
101 * @return \Drupal\Component\Plugin\PluginInspectionInterface
102 * The plugin for the section component being built.
104 public function getPlugin() {
105 return $this->plugin;
109 * Determine if the component is in preview mode.
112 * Whether the component is in preview mode or not.
114 public function inPreview() {
115 return $this->inPreview;
119 * Get the render array in its current state.
122 * The render array built by the event subscribers.
124 public function getBuild() {
129 * Set the render array.
131 * @param array $build
134 public function setBuild(array $build) {
135 $this->build = $build;