annotate core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
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 class SectionComponentBuildRenderArrayEvent extends Event {
Chris@14 18
Chris@14 19 use CacheableResponseTrait;
Chris@14 20
Chris@14 21 /**
Chris@14 22 * The section component whose render array is being built.
Chris@14 23 *
Chris@14 24 * @var \Drupal\layout_builder\SectionComponent
Chris@14 25 */
Chris@14 26 protected $component;
Chris@14 27
Chris@14 28 /**
Chris@14 29 * The available contexts.
Chris@14 30 *
Chris@14 31 * @var \Drupal\Core\Plugin\Context\ContextInterface[]
Chris@14 32 */
Chris@14 33 protected $contexts;
Chris@14 34
Chris@14 35 /**
Chris@14 36 * The plugin for the section component being built.
Chris@14 37 *
Chris@14 38 * @var \Drupal\Component\Plugin\PluginInspectionInterface
Chris@14 39 */
Chris@14 40 protected $plugin;
Chris@14 41
Chris@14 42 /**
Chris@14 43 * Whether the component is in preview mode or not.
Chris@14 44 *
Chris@14 45 * @var bool
Chris@14 46 */
Chris@14 47 protected $inPreview;
Chris@14 48
Chris@14 49 /**
Chris@14 50 * The render array built by the event subscribers.
Chris@14 51 *
Chris@14 52 * @var array
Chris@14 53 */
Chris@14 54 protected $build = [];
Chris@14 55
Chris@14 56 /**
Chris@14 57 * Creates a new SectionComponentBuildRenderArrayEvent object.
Chris@14 58 *
Chris@14 59 * @param \Drupal\layout_builder\SectionComponent $component
Chris@14 60 * The section component whose render array is being built.
Chris@14 61 * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
Chris@14 62 * The available contexts.
Chris@14 63 * @param bool $in_preview
Chris@14 64 * (optional) Whether the component is in preview mode or not.
Chris@14 65 */
Chris@14 66 public function __construct(SectionComponent $component, array $contexts, $in_preview = FALSE) {
Chris@14 67 $this->component = $component;
Chris@14 68 $this->contexts = $contexts;
Chris@14 69 $this->plugin = $component->getPlugin($contexts);
Chris@14 70 $this->inPreview = $in_preview;
Chris@14 71 }
Chris@14 72
Chris@14 73 /**
Chris@14 74 * Get the section component whose render array is being built.
Chris@14 75 *
Chris@14 76 * @return \Drupal\layout_builder\SectionComponent
Chris@14 77 * The section component whose render array is being built.
Chris@14 78 */
Chris@14 79 public function getComponent() {
Chris@14 80 return $this->component;
Chris@14 81 }
Chris@14 82
Chris@14 83 /**
Chris@14 84 * Get the available contexts.
Chris@14 85 *
Chris@14 86 * @return array|\Drupal\Core\Plugin\Context\ContextInterface[]
Chris@14 87 * The available contexts.
Chris@14 88 */
Chris@14 89 public function getContexts() {
Chris@14 90 return $this->contexts;
Chris@14 91 }
Chris@14 92
Chris@14 93 /**
Chris@14 94 * Get the plugin for the section component being built.
Chris@14 95 *
Chris@14 96 * @return \Drupal\Component\Plugin\PluginInspectionInterface
Chris@14 97 * The plugin for the section component being built.
Chris@14 98 */
Chris@14 99 public function getPlugin() {
Chris@14 100 return $this->plugin;
Chris@14 101 }
Chris@14 102
Chris@14 103 /**
Chris@14 104 * Determine if the component is in preview mode.
Chris@14 105 *
Chris@14 106 * @return bool
Chris@14 107 * Whether the component is in preview mode or not.
Chris@14 108 */
Chris@14 109 public function inPreview() {
Chris@14 110 return $this->inPreview;
Chris@14 111 }
Chris@14 112
Chris@14 113 /**
Chris@14 114 * Get the render array in its current state.
Chris@14 115 *
Chris@14 116 * @return array
Chris@14 117 * The render array built by the event subscribers.
Chris@14 118 */
Chris@14 119 public function getBuild() {
Chris@14 120 return $this->build;
Chris@14 121 }
Chris@14 122
Chris@14 123 /**
Chris@14 124 * Set the render array.
Chris@14 125 *
Chris@14 126 * @param array $build
Chris@14 127 * A render array.
Chris@14 128 */
Chris@14 129 public function setBuild(array $build) {
Chris@14 130 $this->build = $build;
Chris@14 131 }
Chris@14 132
Chris@14 133 }