Pull merge.
[yaffs-website] / web / core / lib / Drupal / Component / Plugin / ContextAwarePluginBase.php
index b9f6e02217ad136bb9fe539152250d580f4dfe9c..2d499fd7dd16219f3109daf23a70bb7d3317d881 100644 (file)
@@ -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));
   }
 
   /**