diff --git a/core/lib/Drupal/Core/Field/FieldConfigBase.php b/core/lib/Drupal/Core/Field/FieldConfigBase.php index 957e5a8..1830bb7 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigBase.php +++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php @@ -352,7 +352,7 @@ public function getDescription() { * {@inheritdoc} */ public function getUntranslatedDescription() { - return $this->description; + return $this->getDescription(); } /** diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index c980321..53bb86a 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -76,7 +76,8 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel } $properties['target_id'] = $target_id_definition; $properties['entity'] = DataReferenceDefinition::create('entity') - ->setLabel($target_type_info->getLabel()) + // Set the arguments to NULL so that the label is not translated twice. + ->setLabel($target_type_info->getLabel(), NULL) ->setDescription(nt('The referenced entity')) // The entity object is computed out of the entity ID. ->setComputed(TRUE) diff --git a/core/lib/Drupal/Core/TypedData/DataDefinition.php b/core/lib/Drupal/Core/TypedData/DataDefinition.php index 5fa1c4b..fe5da9d 100644 --- a/core/lib/Drupal/Core/TypedData/DataDefinition.php +++ b/core/lib/Drupal/Core/TypedData/DataDefinition.php @@ -86,19 +86,26 @@ 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 (isset($this->definition['label_arguments'])) { return $this->t($this->definition['label'], $this->definition['label_arguments']); } - return isset($this->definition['label']) ? $this->t($this->definition['label']) : NULL; + // If it was explicitly set to NULL, assume the label is already translated. + return isset($this->definition['label']) ? $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 (isset($this->definition['label_arguments'])) { return String::format($this->definition['label'], $this->definition['label_arguments']); } + // If it was explicitly set to NULL, assume the description is already + // translated. return isset($this->definition['label']) ? $this->definition['label'] : NULL; } @@ -107,10 +114,11 @@ public function getUntranslatedLabel() { * * @param string $label * The label to set. - * @param array $arguments + * @param array|null $arguments * An associative array of replacements to make after translation. Based on * the first character of the key, the value is escaped and/or themed. - * See \Drupal\Component\Utility\String::format() for details. + * See \Drupal\Component\Utility\String::format() for details. NULL means + * that the label is already translated. * * @return static * The object itself for chaining. @@ -146,10 +154,11 @@ public function getUntranslatedDescription() { * * @param string $description * The description to set. - * @param array $arguments + * @param array|null $arguments * An associative array of replacements to make after translation. Based * on the first character of the key, the value is escaped and/or themed. - * See \Drupal\Component\Utility\String::format() for details. + * See \Drupal\Component\Utility\String::format() for details. NULL means + * that the label is already translated. * * @return static * The object itself for chaining. diff --git a/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php b/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php index 9b60891..fbead5a 100644 --- a/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php +++ b/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php @@ -50,6 +50,9 @@ function testTranslatedSchemaDefinition() { 'translation' => 'Translated node ID', ))->save(); + // Ensure that the field is translated when access through the API. + $this->assertEqual('Translated node ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['nid']->getDescription()); + // Assert there are no updates. $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates()); } diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php index a3a7013..107c3b0 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -1220,7 +1220,7 @@ public function setUpStorageDefinition($field_name, array $schema) { ->will($this->returnValue($field_name)); // getDescription() is called once for each table. $this->storageDefinitions[$field_name]->expects($this->any()) - ->method('getDescription') + ->method('getUntranslatedDescription') ->will($this->returnValue("The $field_name field.")); // getSchema() is called once for each table. $this->storageDefinitions[$field_name]->expects($this->any())