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