annotate 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
rev   line source
Chris@14 1 <?php
Chris@14 2
Chris@14 3 namespace Drupal\layout_builder\Event;
Chris@14 4
Chris@14 5 use Drupal\Core\Cache\CacheableResponseTrait;
Chris@14 6 use Drupal\layout_builder\SectionComponent;
Chris@14 7 use Symfony\Component\EventDispatcher\Event;
Chris@14 8
Chris@14 9 /**
Chris@14 10 * Event fired when a section component's render array is being built.
Chris@14 11 *
Chris@14 12 * Subscribers to this event should manipulate the cacheability object and the
Chris@14 13 * build array in this event.
Chris@14 14 *
Chris@14 15 * @see \Drupal\layout_builder\LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY
Chris@14 16 *
Chris@14 17 * @internal
Chris@14 18 * Layout Builder is currently experimental and should only be leveraged by
Chris@14 19 * experimental modules and development releases of contributed modules.
Chris@14 20 * See https://www.drupal.org/core/experimental for more information.
Chris@14 21 */
Chris@14 22 class SectionComponentBuildRenderArrayEvent extends Event {
Chris@14 23
Chris@14 24 use CacheableResponseTrait;
Chris@14 25
Chris@14 26 /**
Chris@14 27 * The section component whose render array is being built.
Chris@14 28 *
Chris@14 29 * @var \Drupal\layout_builder\SectionComponent
Chris@14 30 */
Chris@14 31 protected $component;
Chris@14 32
Chris@14 33 /**
Chris@14 34 * The available contexts.
Chris@14 35 *
Chris@14 36 * @var \Drupal\Core\Plugin\Context\ContextInterface[]
Chris@14 37 */
Chris@14 38 protected $contexts;
Chris@14 39
Chris@14 40 /**
Chris@14 41 * The plugin for the section component being built.
Chris@14 42 *
Chris@14 43 * @var \Drupal\Component\Plugin\PluginInspectionInterface
Chris@14 44 */
Chris@14 45 protected $plugin;
Chris@14 46
Chris@14 47 /**
Chris@14 48 * Whether the component is in preview mode or not.
Chris@14 49 *
Chris@14 50 * @var bool
Chris@14 51 */
Chris@14 52 protected $inPreview;
Chris@14 53
Chris@14 54 /**
Chris@14 55 * The render array built by the event subscribers.
Chris@14 56 *
Chris@14 57 * @var array
Chris@14 58 */
Chris@14 59 protected $build = [];
Chris@14 60
Chris@14 61 /**
Chris@14 62 * Creates a new SectionComponentBuildRenderArrayEvent object.
Chris@14 63 *
Chris@14 64 * @param \Drupal\layout_builder\SectionComponent $component
Chris@14 65 * The section component whose render array is being built.
Chris@14 66 * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
Chris@14 67 * The available contexts.
Chris@14 68 * @param bool $in_preview
Chris@14 69 * (optional) Whether the component is in preview mode or not.
Chris@14 70 */
Chris@14 71 public function __construct(SectionComponent $component, array $contexts, $in_preview = FALSE) {
Chris@14 72 $this->component = $component;
Chris@14 73 $this->contexts = $contexts;
Chris@14 74 $this->plugin = $component->getPlugin($contexts);
Chris@14 75 $this->inPreview = $in_preview;
Chris@14 76 }
Chris@14 77
Chris@14 78 /**
Chris@14 79 * Get the section component whose render array is being built.
Chris@14 80 *
Chris@14 81 * @return \Drupal\layout_builder\SectionComponent
Chris@14 82 * The section component whose render array is being built.
Chris@14 83 */
Chris@14 84 public function getComponent() {
Chris@14 85 return $this->component;
Chris@14 86 }
Chris@14 87
Chris@14 88 /**
Chris@14 89 * Get the available contexts.
Chris@14 90 *
Chris@14 91 * @return array|\Drupal\Core\Plugin\Context\ContextInterface[]
Chris@14 92 * The available contexts.
Chris@14 93 */
Chris@14 94 public function getContexts() {
Chris@14 95 return $this->contexts;
Chris@14 96 }
Chris@14 97
Chris@14 98 /**
Chris@14 99 * Get the plugin for the section component being built.
Chris@14 100 *
Chris@14 101 * @return \Drupal\Component\Plugin\PluginInspectionInterface
Chris@14 102 * The plugin for the section component being built.
Chris@14 103 */
Chris@14 104 public function getPlugin() {
Chris@14 105 return $this->plugin;
Chris@14 106 }
Chris@14 107
Chris@14 108 /**
Chris@14 109 * Determine if the component is in preview mode.
Chris@14 110 *
Chris@14 111 * @return bool
Chris@14 112 * Whether the component is in preview mode or not.
Chris@14 113 */
Chris@14 114 public function inPreview() {
Chris@14 115 return $this->inPreview;
Chris@14 116 }
Chris@14 117
Chris@14 118 /**
Chris@14 119 * Get the render array in its current state.
Chris@14 120 *
Chris@14 121 * @return array
Chris@14 122 * The render array built by the event subscribers.
Chris@14 123 */
Chris@14 124 public function getBuild() {
Chris@14 125 return $this->build;
Chris@14 126 }
Chris@14 127
Chris@14 128 /**
Chris@14 129 * Set the render array.
Chris@14 130 *
Chris@14 131 * @param array $build
Chris@14 132 * A render array.
Chris@14 133 */
Chris@14 134 public function setBuild(array $build) {
Chris@14 135 $this->build = $build;
Chris@14 136 }
Chris@14 137
Chris@14 138 }