Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Render;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
|
Chris@0
|
6 use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
|
Chris@0
|
7 use Drupal\Core\Routing\RouteMatchInterface;
|
Chris@0
|
8 use Symfony\Component\EventDispatcher\Event;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Event fired when rendering main content, to select a page display variant.
|
Chris@0
|
12 *
|
Chris@0
|
13 * Subscribers of this event can call the following setters to pass additional
|
Chris@0
|
14 * information along to the selected variant:
|
Chris@0
|
15 * - self::setPluginConfiguration()
|
Chris@0
|
16 * - self::setContexts()
|
Chris@0
|
17 * - self::addCacheableDependency()
|
Chris@0
|
18 *
|
Chris@0
|
19 * @see \Drupal\Core\Render\RenderEvents::SELECT_PAGE_DISPLAY_VARIANT
|
Chris@0
|
20 * @see \Drupal\Core\Render\MainContent\HtmlRenderer
|
Chris@0
|
21 */
|
Chris@0
|
22 class PageDisplayVariantSelectionEvent extends Event implements RefinableCacheableDependencyInterface {
|
Chris@0
|
23
|
Chris@0
|
24 use RefinableCacheableDependencyTrait;
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * The selected page display variant plugin ID.
|
Chris@0
|
28 *
|
Chris@0
|
29 * @var string
|
Chris@0
|
30 */
|
Chris@0
|
31 protected $pluginId;
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * The configuration for the selected page display variant.
|
Chris@0
|
35 *
|
Chris@0
|
36 * @var array
|
Chris@0
|
37 */
|
Chris@0
|
38 protected $pluginConfiguration = [];
|
Chris@0
|
39
|
Chris@0
|
40 /**
|
Chris@0
|
41 * The current route match.
|
Chris@0
|
42 *
|
Chris@0
|
43 * @var \Drupal\Core\Routing\RouteMatchInterface
|
Chris@0
|
44 */
|
Chris@0
|
45 protected $routeMatch;
|
Chris@0
|
46
|
Chris@0
|
47 /**
|
Chris@0
|
48 * An array of collected contexts to pass to the page display variant.
|
Chris@0
|
49 *
|
Chris@0
|
50 * @var \Drupal\Component\Plugin\Context\ContextInterface[]
|
Chris@0
|
51 */
|
Chris@0
|
52 protected $contexts = [];
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * Constructs the page display variant plugin selection event.
|
Chris@0
|
56 *
|
Chris@0
|
57 * @param string $plugin_id
|
Chris@0
|
58 * The ID of the page display variant plugin to use by default.
|
Chris@0
|
59 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
Chris@0
|
60 * The current route match, for context.
|
Chris@0
|
61 */
|
Chris@0
|
62 public function __construct($plugin_id, RouteMatchInterface $route_match) {
|
Chris@0
|
63 $this->pluginId = $plugin_id;
|
Chris@0
|
64 $this->routeMatch = $route_match;
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@0
|
67 /**
|
Chris@0
|
68 * The selected page display variant plugin ID.
|
Chris@0
|
69 *
|
Chris@0
|
70 * @param string $plugin_id
|
Chris@0
|
71 * The ID of the page display variant plugin to use.
|
Chris@0
|
72 *
|
Chris@0
|
73 * @return $this
|
Chris@0
|
74 */
|
Chris@0
|
75 public function setPluginId($plugin_id) {
|
Chris@0
|
76 $this->pluginId = $plugin_id;
|
Chris@0
|
77 return $this;
|
Chris@0
|
78 }
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * The selected page display variant plugin ID.
|
Chris@0
|
82 *
|
Chris@0
|
83 * @return string
|
Chris@0
|
84 */
|
Chris@0
|
85 public function getPluginId() {
|
Chris@0
|
86 return $this->pluginId;
|
Chris@0
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 /**
|
Chris@0
|
90 * Set the configuration for the selected page display variant.
|
Chris@0
|
91 *
|
Chris@0
|
92 * @param array $configuration
|
Chris@0
|
93 * The configuration for the selected page display variant.
|
Chris@0
|
94 *
|
Chris@0
|
95 * @return $this
|
Chris@0
|
96 */
|
Chris@0
|
97 public function setPluginConfiguration(array $configuration) {
|
Chris@0
|
98 $this->pluginConfiguration = $configuration;
|
Chris@0
|
99 return $this;
|
Chris@0
|
100 }
|
Chris@0
|
101
|
Chris@0
|
102 /**
|
Chris@0
|
103 * Get the configuration for the selected page display variant.
|
Chris@0
|
104 *
|
Chris@0
|
105 * @return array
|
Chris@0
|
106 */
|
Chris@0
|
107 public function getPluginConfiguration() {
|
Chris@0
|
108 return $this->pluginConfiguration;
|
Chris@0
|
109 }
|
Chris@0
|
110
|
Chris@0
|
111 /**
|
Chris@0
|
112 * Gets the current route match.
|
Chris@0
|
113 *
|
Chris@0
|
114 * @return \Drupal\Core\Routing\RouteMatchInterface
|
Chris@0
|
115 * The current route match, for context.
|
Chris@0
|
116 */
|
Chris@0
|
117 public function getRouteMatch() {
|
Chris@0
|
118 return $this->routeMatch;
|
Chris@0
|
119 }
|
Chris@0
|
120
|
Chris@0
|
121 /**
|
Chris@0
|
122 * Gets the contexts that were set during event dispatch.
|
Chris@0
|
123 *
|
Chris@0
|
124 * @return \Drupal\Component\Plugin\Context\ContextInterface[]
|
Chris@0
|
125 * An array of set contexts, keyed by context name.
|
Chris@0
|
126 */
|
Chris@0
|
127 public function getContexts() {
|
Chris@0
|
128 return $this->contexts;
|
Chris@0
|
129 }
|
Chris@0
|
130
|
Chris@0
|
131 /**
|
Chris@0
|
132 * Sets the contexts to be passed to the page display variant.
|
Chris@0
|
133 *
|
Chris@0
|
134 * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
|
Chris@0
|
135 * An array of contexts, keyed by context name.
|
Chris@0
|
136 *
|
Chris@0
|
137 * @return $this
|
Chris@0
|
138 */
|
Chris@0
|
139 public function setContexts(array $contexts) {
|
Chris@0
|
140 $this->contexts = $contexts;
|
Chris@0
|
141 return $this;
|
Chris@0
|
142 }
|
Chris@0
|
143
|
Chris@0
|
144 }
|