diff --git a/core/lib/Drupal/Core/Annotation/ContextDefinition.php b/core/lib/Drupal/Core/Annotation/ContextDefinition.php index 3508c57..587d632 100644 --- a/core/lib/Drupal/Core/Annotation/ContextDefinition.php +++ b/core/lib/Drupal/Core/Annotation/ContextDefinition.php @@ -9,6 +9,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\Annotation\Translation; /** * @defgroup plugin_context Annotation for context definition @@ -113,8 +114,17 @@ public function __construct(array $values) { // used in the classes they pass to. foreach (['label', 'description'] as $key) { // @todo Remove this workaround in https://www.drupal.org/node/2362727. - if (isset($values[$key]) && $values[$key] instanceof TranslatableMarkup) { - $values[$key] = (string) $values[$key]->get(); + if (isset($values[$key])) { + $value = $values[$key]; + if ($value instanceof TranslatableMarkup) { + $values[$key] = (string) $value->get(); + } + elseif ($values[$key] instanceof Translation) { + $values[$key] = (string) $value; + } + else { + $values[$key] = NULL; + } } else { $values[$key] = NULL; diff --git a/core/lib/Drupal/Core/Annotation/Translation.php b/core/lib/Drupal/Core/Annotation/Translation.php index 83cd6f6..3332ac9 100644 --- a/core/lib/Drupal/Core/Annotation/Translation.php +++ b/core/lib/Drupal/Core/Annotation/Translation.php @@ -96,4 +96,11 @@ public function get() { return $this->translation; } + /** + * Since Translate annotations can be used in the UI, allow conversion to string. + */ + public function __toString() { + return $this->translation->render(); + } + }