diff core/lib/Drupal/Core/Annotation/ContextDefinition.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Annotation/ContextDefinition.php	Thu Feb 28 13:11:55 2019 +0000
+++ b/core/lib/Drupal/Core/Annotation/ContextDefinition.php	Thu May 09 15:34:47 2019 +0100
@@ -14,14 +14,14 @@
  * interactions through providing limits, and mapping contexts to appropriate
  * plugins. Context definitions can be provided as such:
  * @code
- *   context = {
+ *   context_definitions = {
  *     "node" = @ContextDefinition("entity:node")
  *   }
  * @endcode
  *
  * To add a label to a context definition use the "label" key:
  * @code
- *   context = {
+ *   context_definitions = {
  *     "node" = @ContextDefinition("entity:node", label = @Translation("Node"))
  *   }
  * @endcode
@@ -29,7 +29,7 @@
  * Contexts are required unless otherwise specified. To make an optional
  * context use the "required" key:
  * @code
- *   context = {
+ *   context_definitions = {
  *     "node" = @ContextDefinition("entity:node", required = FALSE, label = @Translation("Node"))
  *   }
  * @endcode
@@ -37,7 +37,7 @@
  * To define multiple contexts, simply provide different key names in the
  * context array:
  * @code
- *   context = {
+ *   context_definitions = {
  *     "artist" = @ContextDefinition("entity:node", label = @Translation("Artist")),
  *     "album" = @ContextDefinition("entity:node", label = @Translation("Album"))
  *   }
@@ -45,7 +45,7 @@
  *
  * Specifying a default value for the context definition:
  * @code
- *   context = {
+ *   context_definitions = {
  *     "message" = @ContextDefinition("string",
  *       label = @Translation("Message"),
  *       default_value = @Translation("Checkout complete! Thank you for your purchase.")
@@ -119,6 +119,12 @@
 
     $class = $this->getDefinitionClass($values);
     $this->definition = new $class($values['value'], $values['label'], $values['required'], $values['multiple'], $values['description'], $values['default_value']);
+
+    if (isset($values['constraints'])) {
+      foreach ($values['constraints'] as $constraint_name => $options) {
+        $this->definition->addConstraint($constraint_name, $options);
+      }
+    }
   }
 
   /**