PluginContextDefinitionTrait.php in Plugin 8.2
File
src/PluginDefinition/PluginContextDefinitionTrait.php
View source
<?php
namespace Drupal\plugin\PluginDefinition;
use Drupal\Component\Plugin\Context\ContextDefinitionInterface;
trait PluginContextDefinitionTrait {
protected $contextDefinitions = [];
public function setContextDefinitions(array $context_definitions) {
PluginDefinitionValidator::validateContextDefinitions($context_definitions);
$this->contextDefinitions = $context_definitions;
return $this;
}
public function getContextDefinitions() {
return $this->contextDefinitions;
}
public function setContextDefinition($name, ContextDefinitionInterface $context_definition) {
$this->contextDefinitions[$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->contextDefinitions[$name];
}
public function hasContextDefinition($name) {
return isset($this->contextDefinitions[$name]);
}
}