EmbedTypeBase.php in Embed 8
File
src/EmbedType/EmbedTypeBase.php
View source
<?php
namespace Drupal\embed\EmbedType;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
abstract class EmbedTypeBase extends PluginBase implements EmbedTypeInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $this->configuration);
}
public function calculateDependencies() {
return [];
}
public function defaultConfiguration() {
return [];
}
public function getConfiguration() {
return $this->configuration;
}
public function getConfigurationValue($name, $default = NULL) {
$configuration = $this
->getConfiguration();
if (array_key_exists($name, $configuration)) {
return $configuration[$name];
}
else {
return $default;
}
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
public function setConfigurationValue($name, $value) {
$this->configuration[$name] = $value;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
if (!$form_state
->hasAnyErrors()) {
$this
->setConfiguration(array_intersect_key($form_state
->getValues(), $this
->defaultConfiguration()));
}
}
}
Classes
Name |
Description |
EmbedTypeBase |
Defines a base implementation that most embed type plugins will extend. |