ArrayPluginDefinitionDecorator.php in Plugin 8.2
File
src/PluginDefinition/ArrayPluginDefinitionDecorator.php
View source
<?php
namespace Drupal\plugin\PluginDefinition;
use Drupal\Component\Plugin\Context\ContextDefinitionInterface;
use Drupal\Component\Utility\NestedArray;
class ArrayPluginDefinitionDecorator implements ArrayPluginDefinitionInterface, PluginContextDefinitionInterface, PluginDeriverDefinitionInterface, PluginLabelDefinitionInterface, PluginDescriptionDefinitionInterface, PluginCategoryDefinitionInterface, PluginConfigDependenciesDefinitionInterface, PluginDefinitionDecoratorInterface, PluginHierarchyDefinitionInterface, PluginOperationsProviderDefinitionInterface {
use MergeablePluginDefinitionTrait;
protected $arrayDefinition = [];
public function __construct(array $array_definition = []) {
if (isset($array_definition['class'])) {
PluginDefinitionValidator::validateClass($array_definition['class']);
}
if (isset($array_definition['deriver'])) {
PluginDefinitionValidator::validateDeriverClass($array_definition['deriver']);
}
if (isset($array_definition['context'])) {
PluginDefinitionValidator::validateContextDefinitions($array_definition['context']);
}
$this->arrayDefinition = $array_definition;
}
public static function createFromDecoratedDefinition($decorated_plugin_definition) {
if (!is_array($decorated_plugin_definition)) {
$type = is_object($decorated_plugin_definition) ? get_class($decorated_plugin_definition) : gettype($decorated_plugin_definition);
throw new \InvalidArgumentException(sprintf('The decorated plugin definition must be an array, but %s given.', $type));
}
return new static($decorated_plugin_definition);
}
public function getArrayDefinition() {
return $this->arrayDefinition;
}
public function mergeDefaultArrayDefinition(array $other_definition) {
$this->arrayDefinition = NestedArray::mergeDeepArray([
$other_definition,
$this->arrayDefinition,
], TRUE);
return $this;
}
public function mergeOverrideArrayDefinition(array $other_definition) {
$this->arrayDefinition = NestedArray::mergeDeepArray([
$this->arrayDefinition,
$other_definition,
], TRUE);
return $this;
}
public function setId($id) {
$this->arrayDefinition['id'] = $id;
return $this;
}
public function id() {
return isset($this->arrayDefinition['id']) ? $this->arrayDefinition['id'] : NULL;
}
public function getId() {
return $this
->id();
}
public function setClass($class) {
PluginDefinitionValidator::validateClass($class);
$this->arrayDefinition['class'] = $class;
return $this;
}
public function getClass() {
return isset($this->arrayDefinition['class']) ? $this->arrayDefinition['class'] : NULL;
}
public function setLabel($label) {
$this->arrayDefinition['label'] = $label;
return $this;
}
public function getLabel() {
return isset($this->arrayDefinition['label']) ? $this->arrayDefinition['label'] : NULL;
}
public function setDescription($description) {
$this->arrayDefinition['description'] = $description;
return $this;
}
public function getDescription() {
return isset($this->arrayDefinition['description']) ? $this->arrayDefinition['description'] : NULL;
}
public function setDeriverClass($class) {
PluginDefinitionValidator::validateDeriverClass($class);
$this->arrayDefinition['deriver'] = $class;
return $this;
}
public function getDeriverClass() {
return isset($this->arrayDefinition['deriver']) ? $this->arrayDefinition['deriver'] : NULL;
}
public function setProvider($provider) {
$this->arrayDefinition['provider'] = $provider;
return $this;
}
public function getProvider() {
return isset($this->arrayDefinition['provider']) ? $this->arrayDefinition['provider'] : NULL;
}
public function setCategory($category) {
$this->arrayDefinition['category'] = $category;
return $this;
}
public function getCategory() {
return isset($this->arrayDefinition['category']) ? $this->arrayDefinition['category'] : NULL;
}
public function setConfigDependencies(array $dependencies) {
$this->arrayDefinition['config_dependencies'] = $dependencies;
return $this;
}
public function getConfigDependencies() {
return isset($this->arrayDefinition['config_dependencies']) ? $this->arrayDefinition['config_dependencies'] : [];
}
public function setContextDefinitions(array $context_definitions) {
PluginDefinitionValidator::validateContextDefinitions($context_definitions);
$this->arrayDefinition['context'] = $context_definitions;
return $this;
}
public function getContextDefinitions() {
return isset($this->arrayDefinition['context']) ? $this->arrayDefinition['context'] : [];
}
public function setContextDefinition($name, ContextDefinitionInterface $context_definition) {
$this->arrayDefinition['context'][$name] = $context_definition;
return $this;
}
public function getContextDefinition($name) {
if (!$this
->hasContextDefinition($name)) {
throw new \InvalidArgumentException(sprintf('Context %s does not exist.', $name));
}
return $this->arrayDefinition['context'][$name];
}
public function hasContextDefinition($name) {
return isset($this->arrayDefinition['context'][$name]);
}
public function doMergeDefaultDefinition(PluginDefinitionInterface $other_definition) {
$this
->mergeDefaultArrayDefinition($other_definition
->getArrayDefinition());
}
public function doMergeOverrideDefinition(PluginDefinitionInterface $other_definition) {
$this
->mergeOverrideArrayDefinition($other_definition
->getArrayDefinition());
}
protected function isDefinitionCompatible(PluginDefinitionInterface $other_definition) {
return $other_definition instanceof $this;
}
public function offsetExists($offset) {
return isset($this->arrayDefinition[$offset]);
}
public function &offsetGet($offset) {
return $this->arrayDefinition[$offset];
}
public function offsetSet($offset, $value) {
switch ($offset) {
case 'class':
$this
->setClass($value);
break;
case 'deriver':
$this
->setDeriverClass($value);
break;
case 'context':
$this
->setContextDefinitions($value);
break;
default:
$this->arrayDefinition[$offset] = $value;
break;
}
}
public function offsetUnset($offset) {
unset($this->arrayDefinition[$offset]);
}
public function count() {
return count($this->arrayDefinition);
}
public function getIterator() {
return new \ArrayIterator($this->arrayDefinition);
}
public function setParentId($id) {
$this->arrayDefinition['parent_id'] = $id;
return $this;
}
public function getParentId() {
return isset($this->arrayDefinition['parent_id']) ? $this->arrayDefinition['parent_id'] : NULL;
}
public function setOperationsProviderClass($class) {
$this->arrayDefinition['operations_provider'] = $class;
return $this;
}
public function getOperationsProviderClass() {
return isset($this->arrayDefinition['operations_provider']) ? $this->arrayDefinition['operations_provider'] : NULL;
}
}