diff --git a/core/lib/Drupal/Core/Annotation/ContextDefinition.php b/core/lib/Drupal/Core/Annotation/ContextDefinition.php index ecf6eeb..88ed409 100644 --- a/core/lib/Drupal/Core/Annotation/ContextDefinition.php +++ b/core/lib/Drupal/Core/Annotation/ContextDefinition.php @@ -94,21 +94,21 @@ public function __construct(array $values) { $values += array( 'required' => TRUE, 'multiple' => FALSE, - 'label' => NULL, - 'description' => NULL, ); + // Annotation classes extract data from passed annotation classes directly + // used in the classes they pass to. + foreach (['label', 'description'] as $key) { + if (isset($values[$key]) && $values[$key] instanceof TranslationWrapper) { + $values[$key] = (string) $values[$key]->get(); + } + else { + $values[$key] = NULL; + } + } if (isset($values['class']) && !in_array('Drupal\Core\Plugin\Context\ContextDefinitionInterface', class_implements($values['class']))) { throw new \Exception('ContextDefinition class must implement \Drupal\Core\Plugin\Context\ContextDefinitionInterface.'); } $class = isset($values['class']) ? $values['class'] : 'Drupal\Core\Plugin\Context\ContextDefinition'; - - // Make sure that we don't pass Translation objects to the - // ContextDefinition, it expects plain strings. - foreach (array('label', 'description') as $translatable) { - if ($values[$translatable] instanceof Translation) { - $values[$translatable] = (string) $values[$translatable]->get(); - } - } $this->definition = new $class($values['value'], $values['label'], $values['required'], $values['multiple'], $values['description']); } diff --git a/core/modules/action/src/Plugin/Action/EmailAction.php b/core/modules/action/src/Plugin/Action/EmailAction.php index 48ddd37..428de7a 100644 --- a/core/modules/action/src/Plugin/Action/EmailAction.php +++ b/core/modules/action/src/Plugin/Action/EmailAction.php @@ -27,9 +27,9 @@ * description = @Translation("The contextual entity that can be used for token replacements."), * required = false * ), - * "recipient" = @ContextDefinition("string", + * "recipient" = @ContextDefinition("email", * label = @Translation("Recipient"), - * description = @Translation("The email address to which the message should be sent OR enter [node:author:mail], [comment:author:mail], etc. if you would like to send an email to the author of the original post.") + * description = @Translation("The email address to which the message should be sent.") * ), * "subject" = @ContextDefinition("string", * label = @Translation("Subject"), @@ -37,7 +37,7 @@ * ), * "message" = @ContextDefinition("string", * label = @Translation("Message"), - * description = @Translation("The message that should be sent. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.") + * description = @Translation("The message that should be sent.") * ), * } * ) diff --git a/core/modules/action/src/Plugin/Action/MessageAction.php b/core/modules/action/src/Plugin/Action/MessageAction.php index 05f1956..8d8b2d2 100644 --- a/core/modules/action/src/Plugin/Action/MessageAction.php +++ b/core/modules/action/src/Plugin/Action/MessageAction.php @@ -21,9 +21,9 @@ * id = "action_message_action", * label = @Translation("Display a message to the user"), * context = { - * "entity" = @ContextDefinition("entity", - * label = @Translation("Entity"), - * description = @Translation("The contextual entity that can be used for token replacements."), + * "node" = @ContextDefinition("entity:node", + * label = @Translation("Node"), + * description = @Translation("The contextual node entity that can be used for token replacements."), * required = false * ), * "message" = @ContextDefinition("string", @@ -71,9 +71,9 @@ public function execute() { * should solely depend on context. */ protected function mapConfigurationToContext() { - $entity = $this->getContextValue('entity'); - if (empty($this->configuration['node']) && $entity) { - $this->configuration['node'] = $entity; + $node = $this->getContextValue('node'); + if (empty($this->configuration['node']) && $node) { + $this->configuration['node'] = $node; } // First check if a message context value is set, otherwise use the value