diff --git a/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php index 9b0eb65..edc7cf3 100644 --- a/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php @@ -113,26 +113,39 @@ public function isRevisionable(); public function isQueryable(); /** - * Returns the human-readable label for the field. + * Returns a human readable label. * - * @return string - * The field label. + * @return \Drupal\Core\StringTranslation\TranslationWrapper|null + * The label wrapped for translation, or NULL if no label is available. */ public function getLabel(); /** - * Returns the human-readable description for the field. + * Returns an untranslated human readable label. * - * This is displayed in addition to the label in places where additional - * descriptive information is helpful. For example, as help text below the - * form element in entity edit forms. + * @return string + * The label. + */ + public function getUntranslatedLabel(); + + /** + * Returns a human readable description. * - * @return string|null - * The field description, or NULL if no description is available. + * @return \Drupal\Core\StringTranslation\TranslationWrapper|null + * The description wrapped for translation, or NULL if no description is + * available. */ public function getDescription(); /** + * Returns an untranslated human readable description. + * + * @return string|null + * The description, or NULL if no description is available. + */ + public function getUntranslatedDescription(); + + /** * Gets an options provider for the given field item property. * * @param string $property_name diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php index 1285cb7..be7dada 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php @@ -7,6 +7,8 @@ namespace Drupal\Core\StringTranslation; +use Drupal\Component\Utility\String; + /** * Provides a class to wrap a translatable string. * @@ -67,7 +69,7 @@ public function __toString() { } /** - * Renders the object as a string. + * Renders the object as a translated string. * * @return string * The translated string. @@ -77,6 +79,16 @@ public function render() { } /** + * Renders the object as an untranslated string. + * + * @return string + * The untranslated string. + */ + public function getUntranslated() { + return String::format($this->string, $this->arguments); + } + + /** * Magic __sleep() method to avoid serializing the string translator. */ public function __sleep() { diff --git a/core/lib/Drupal/Core/TypedData/DataDefinition.php b/core/lib/Drupal/Core/TypedData/DataDefinition.php index fe5da9d..352a031 100644 --- a/core/lib/Drupal/Core/TypedData/DataDefinition.php +++ b/core/lib/Drupal/Core/TypedData/DataDefinition.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\StringTranslation\TranslationWrapper; /** * A typed data definition class for defining data based on defined data types. @@ -86,21 +87,22 @@ public function setDataType($type) { * {@inheritdoc} */ public function getLabel() { - // If label_arguments is an array (by default, it is an empty array), - // translate the label. + if ($this->definition['label'] instanceof TranslationWrapper) { + return $this->definition['label']; + } if (isset($this->definition['label_arguments'])) { - return $this->t($this->definition['label'], $this->definition['label_arguments']); + return new TranslationWrapper($this->definition['description'], $this->definition['label_arguments']); } - // If it was explicitly set to NULL, assume the label is already translated. - return isset($this->definition['label']) ? $this->definition['label'] : NULL; + return isset($this->definition['label']) ? new TranslationWrapper($this->definition['label']) : NULL; } /** * {@inheritdoc} */ public function getUntranslatedLabel() { - // If description_arguments is an array (by default, it is an empty array), - // translate the label. + if ($this->definition['label'] instanceof TranslationWrapper) { + return $this->definition['label']->getUntranslated(); + } if (isset($this->definition['label_arguments'])) { return String::format($this->definition['label'], $this->definition['label_arguments']); } @@ -133,10 +135,13 @@ public function setLabel($label, $arguments = array()) { * {@inheritdoc} */ public function getDescription() { + if ($this->definition['description'] instanceof TranslationWrapper) { + return $this->definition['description']; + } if (isset($this->definition['description_arguments'])) { - return $this->t($this->definition['description'], $this->definition['description_arguments']); + return new TranslationWrapper($this->definition['description'], $this->definition['description_arguments']); } - return isset($this->definition['description']) ? $this->t($this->definition['description']) : NULL; + return isset($this->definition['description']) ? new TranslationWrapper($this->definition['description']) : NULL; } /** diff --git a/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php b/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php index d7df9db..1b2a578 100644 --- a/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php +++ b/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php @@ -62,8 +62,8 @@ public function getDataType(); /** * Returns a human readable label. * - * @return string - * The label. + * @return \Drupal\Core\StringTranslation\TranslationWrapper|null + * The label wrapped for translation, or NULL if no label is available. */ public function getLabel(); @@ -78,8 +78,9 @@ public function getUntranslatedLabel(); /** * Returns a human readable description. * - * @return string|null - * The description, or NULL if no description is available. + * @return \Drupal\Core\StringTranslation\TranslationWrapper|null + * The description wrapped for translation, or NULL if no description is + * available. */ public function getDescription();