1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains \Drupal\embed\EmbedType\EmbedTypeBase. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Drupal\embed\EmbedType; |
9
|
|
|
|
10
|
|
|
use Drupal\Component\Utility\NestedArray; |
11
|
|
|
use Drupal\Core\Form\FormStateInterface; |
12
|
|
|
use Drupal\Core\Plugin\PluginBase; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Defines a base implementation that most embed type plugins will extend. |
16
|
|
|
* |
17
|
|
|
* @ingroup embed_api |
18
|
|
|
*/ |
19
|
|
|
abstract class EmbedTypeBase extends PluginBase implements EmbedTypeInterface { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function __construct(array $configuration, $plugin_id, $plugin_definition) { |
25
|
|
|
parent::__construct($configuration, $plugin_id, $plugin_definition); |
26
|
|
|
$this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $this->configuration); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function calculateDependencies() { |
33
|
|
|
return []; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function defaultConfiguration() { |
40
|
|
|
return []; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function getConfiguration() { |
47
|
|
|
return $this->configuration; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getConfigurationValue($name, $default = NULL) { |
54
|
|
|
$configuration = $this->getConfiguration(); |
55
|
|
|
if (array_key_exists($name, $configuration)) { |
56
|
|
|
return $configuration[$name]; |
57
|
|
|
} |
58
|
|
|
else { |
59
|
|
|
return $default; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function setConfiguration(array $configuration) { |
67
|
|
|
$this->configuration = $configuration; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function setConfigurationValue($name, $value) { |
74
|
|
|
$this->configuration[$name] = $value; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function buildConfigurationForm(array $form, FormStateInterface $form_state) { |
81
|
|
|
return $form; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { |
88
|
|
|
// Do nothing. |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { |
95
|
|
|
if (!$form_state->hasAnyErrors()) { |
96
|
|
|
$this->setConfiguration( |
97
|
|
|
array_intersect_key( |
98
|
|
|
$form_state->getValues(), |
99
|
|
|
$this->defaultConfiguration() |
100
|
|
|
) |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|