comparison core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children af1871eacc83
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2
3 namespace Drupal\layout_builder\Event;
4
5 use Drupal\Core\Cache\CacheableResponseTrait;
6 use Drupal\layout_builder\SectionComponent;
7 use Symfony\Component\EventDispatcher\Event;
8
9 /**
10 * Event fired when a section component's render array is being built.
11 *
12 * Subscribers to this event should manipulate the cacheability object and the
13 * build array in this event.
14 *
15 * @see \Drupal\layout_builder\LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY
16 *
17 * @internal
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.
21 */
22 class SectionComponentBuildRenderArrayEvent extends Event {
23
24 use CacheableResponseTrait;
25
26 /**
27 * The section component whose render array is being built.
28 *
29 * @var \Drupal\layout_builder\SectionComponent
30 */
31 protected $component;
32
33 /**
34 * The available contexts.
35 *
36 * @var \Drupal\Core\Plugin\Context\ContextInterface[]
37 */
38 protected $contexts;
39
40 /**
41 * The plugin for the section component being built.
42 *
43 * @var \Drupal\Component\Plugin\PluginInspectionInterface
44 */
45 protected $plugin;
46
47 /**
48 * Whether the component is in preview mode or not.
49 *
50 * @var bool
51 */
52 protected $inPreview;
53
54 /**
55 * The render array built by the event subscribers.
56 *
57 * @var array
58 */
59 protected $build = [];
60
61 /**
62 * Creates a new SectionComponentBuildRenderArrayEvent object.
63 *
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.
70 */
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;
76 }
77
78 /**
79 * Get the section component whose render array is being built.
80 *
81 * @return \Drupal\layout_builder\SectionComponent
82 * The section component whose render array is being built.
83 */
84 public function getComponent() {
85 return $this->component;
86 }
87
88 /**
89 * Get the available contexts.
90 *
91 * @return array|\Drupal\Core\Plugin\Context\ContextInterface[]
92 * The available contexts.
93 */
94 public function getContexts() {
95 return $this->contexts;
96 }
97
98 /**
99 * Get the plugin for the section component being built.
100 *
101 * @return \Drupal\Component\Plugin\PluginInspectionInterface
102 * The plugin for the section component being built.
103 */
104 public function getPlugin() {
105 return $this->plugin;
106 }
107
108 /**
109 * Determine if the component is in preview mode.
110 *
111 * @return bool
112 * Whether the component is in preview mode or not.
113 */
114 public function inPreview() {
115 return $this->inPreview;
116 }
117
118 /**
119 * Get the render array in its current state.
120 *
121 * @return array
122 * The render array built by the event subscribers.
123 */
124 public function getBuild() {
125 return $this->build;
126 }
127
128 /**
129 * Set the render array.
130 *
131 * @param array $build
132 * A render array.
133 */
134 public function setBuild(array $build) {
135 $this->build = $build;
136 }
137
138 }