X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FComponent%2FPlugin%2FContextAwarePluginBase.php;fp=web%2Fcore%2Flib%2FDrupal%2FComponent%2FPlugin%2FContextAwarePluginBase.php;h=2d499fd7dd16219f3109daf23a70bb7d3317d881;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=b9f6e02217ad136bb9fe539152250d580f4dfe9c;hpb=9424afc6c1f518c301bf87a23c047d1873435d05;p=yaffs-website diff --git a/web/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php b/web/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php index b9f6e0221..2d499fd7d 100644 --- a/web/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php +++ b/web/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php @@ -3,6 +3,7 @@ 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; @@ -67,7 +68,12 @@ abstract class ContextAwarePluginBase extends PluginBase implements ContextAware */ 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'] : []; + } } /** @@ -75,10 +81,15 @@ abstract class ContextAwarePluginBase extends PluginBase implements ContextAware */ 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)); } /**