annotate core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php @ 5:12f9dff5fda9 tip

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