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