namespace Drupal\Component\Plugin;
use Drupal\Component\Plugin\Context\ContextInterface;
+use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface;
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Component\Plugin\Context\Context;
use Symfony\Component\Validator\ConstraintViolationList;
*/
public function getContextDefinitions() {
$definition = $this->getPluginDefinition();
- return !empty($definition['context']) ? $definition['context'] : [];
+ if ($definition instanceof ContextAwarePluginDefinitionInterface) {
+ return $definition->getContextDefinitions();
+ }
+ else {
+ return !empty($definition['context']) ? $definition['context'] : [];
+ }
}
/**
*/
public function getContextDefinition($name) {
$definition = $this->getPluginDefinition();
- if (empty($definition['context'][$name])) {
- throw new ContextException(sprintf("The %s context is not a valid context.", $name));
+ if ($definition instanceof ContextAwarePluginDefinitionInterface) {
+ if ($definition->hasContextDefinition($name)) {
+ return $definition->getContextDefinition($name);
+ }
+ }
+ elseif (!empty($definition['context'][$name])) {
+ return $definition['context'][$name];
}
- return $definition['context'][$name];
+ throw new ContextException(sprintf("The %s context is not a valid context.", $name));
}
/**