1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\entity_browser; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Uuid\UuidInterface; |
6
|
|
|
use Drupal\Core\Plugin\PluginBase; |
7
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
9
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base implementation for display plugins. |
13
|
|
|
*/ |
14
|
|
|
abstract class DisplayBase extends PluginBase implements DisplayInterface, ContainerFactoryPluginInterface { |
15
|
|
|
|
16
|
|
|
use PluginConfigurationFormTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Plugin label. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $label; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Selected entities. |
27
|
|
|
* |
28
|
|
|
* @var \Drupal\Core\Entity\EntityInterface[] |
29
|
|
|
*/ |
30
|
|
|
protected $entities = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Event dispatcher service. |
34
|
|
|
* |
35
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
36
|
|
|
*/ |
37
|
|
|
protected $eventDispatcher; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* UUID generator interface. |
41
|
|
|
* |
42
|
|
|
* @var \Drupal\Component\Uuid\UuidInterface |
43
|
|
|
*/ |
44
|
|
|
protected $uuidGenerator; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Instance UUID string. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $uuid = NULL; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Constructs display plugin. |
55
|
|
|
* |
56
|
|
|
* @param array $configuration |
57
|
|
|
* A configuration array containing information about the plugin instance. |
58
|
|
|
* @param string $plugin_id |
59
|
|
|
* The plugin_id for the plugin instance. |
60
|
|
|
* @param mixed $plugin_definition |
61
|
|
|
* The plugin implementation definition. |
62
|
|
|
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher |
63
|
|
|
* Event dispatcher service. |
64
|
|
|
* @param \Drupal\Component\Uuid\UuidInterface |
65
|
|
|
* UUID generator interface. |
66
|
|
|
*/ |
67
|
|
|
public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, UuidInterface $uuid_generator) { |
68
|
|
|
parent::__construct($configuration, $plugin_id, $plugin_definition); |
69
|
|
|
$this->configuration += $this->defaultConfiguration(); |
70
|
|
|
$this->eventDispatcher = $event_dispatcher; |
71
|
|
|
$this->uuidGenerator = $uuid_generator; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
78
|
|
|
return new static( |
79
|
|
|
$configuration, |
80
|
|
|
$plugin_id, |
81
|
|
|
$plugin_definition, |
82
|
|
|
$container->get('event_dispatcher'), |
83
|
|
|
$container->get('uuid') |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
|
public function defaultConfiguration() { |
91
|
|
|
return []; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function getConfiguration() { |
98
|
|
|
return array_diff_key( |
99
|
|
|
$this->configuration, |
100
|
|
|
['entity_browser_id' => 0] |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
|
public function setConfiguration(array $configuration) { |
108
|
|
|
$this->configuration = $configuration; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
*/ |
114
|
|
|
public function calculateDependencies() { |
115
|
|
|
return []; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function label() { |
122
|
|
|
return $this->label; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
*/ |
128
|
|
|
public function getUuid() { |
129
|
|
|
if (empty($this->uuid)) { |
130
|
|
|
$this->uuid = $this->uuidGenerator->generate(); |
131
|
|
|
} |
132
|
|
|
return $this->uuid; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* {@inheritdoc} |
137
|
|
|
*/ |
138
|
|
|
public function setUuid($uuid) { |
139
|
|
|
$this->uuid = $uuid; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|