diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 7c68f0ab458f0afde2c3794cb116be52a1082397..d62c4047b57ae2f62783475d160362e5d9835ffb 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -945,17 +945,14 @@ public function __clone() { } /** - * Overrides Entity::label() to access the label field with the new API. + * {@inheritdoc} */ - public function label($langcode = NULL) { + public function label() { $label = NULL; $entity_info = $this->entityInfo(); - if (!isset($langcode)) { - $langcode = $this->activeLangcode; - } // @todo Convert to is_callable() and call_user_func(). if (($label_callback = $entity_info->getLabelCallback()) && function_exists($label_callback)) { - $label = $label_callback($this, $langcode); + $label = $label_callback($this); } elseif (($label_key = $entity_info->getKey('label')) && isset($this->{$label_key})) { $label = $this->{$label_key}->value; diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 178fe51d1a546f93b01a4d8b5815a6138f79e99b..2e4a7eab6cfb57ad33d4ce48014008459dbdd06a 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -106,12 +106,12 @@ public function bundle() { /** * {@inheritdoc} */ - public function label($langcode = NULL) { + public function label() { $label = NULL; $entity_info = $this->entityInfo(); // @todo Convert to is_callable() and call_user_func(). if (($label_callback = $entity_info->getLabelCallback()) && function_exists($label_callback)) { - $label = $label_callback($this, $langcode); + $label = $label_callback($this); } elseif (($label_key = $entity_info->getKey('label')) && isset($this->{$label_key})) { $label = $this->{$label_key}; diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 66ed701d5b085b08010026c27f2a74c6bfdea551..b9f1d5e199455ba15f9a65ef25e42b877c0ad57d 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -89,15 +89,10 @@ public function bundle(); /** * Returns the label of the entity. * - * @param $langcode - * (optional) The language code of the language that should be used for - * getting the label. If set to NULL, the entity's active language is - * used. - * * @return * The label of the entity, or NULL if there is no label defined. */ - public function label($langcode = NULL); + public function label(); /** * Returns the URI elements of the entity. diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 1f9cff312268593041d36f8a0eade6794c6b17fc..4cb05aac17b1d00528fc1e9a8c589e3d14a763c6 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -371,15 +371,15 @@ public function setLinkTemplate($key, $route_name); /** * Gets the callback for the label of the entity. * - * The function takes an entity and optional langcode argument, and returns - * the label of the entity. If langcode is omitted, the entity's default - * language is used. The entity label is the main string associated with an - * entity; for example, the title of a node or the subject of a comment. If - * there is an entity object property that defines the label, use the 'label' - * element of the 'entity_keys' return value component to provide this - * information (see below). If more complex logic is needed to determine the - * label of an entity, you can instead specify a callback function here, which - * will be called to determine the entity label. See also the + * The function takes an entity and returns the label of the entity. Use + * language() on the entity to get information on the requested language. The + * entity label is the main string associated with an entity; for example, the + * title of a node or the subject of a comment. If there is an entity object + * property that defines the label, use the 'label' element of the + * 'entity_keys' return value component to provide this information (see + * below). If more complex logic is needed to determine the label of an + * entity, you can instead specify a callback function here, which will be + * called to determine the entity label. See also the * \Drupal\Core\Entity\EntityInterface::label() method, which implements this * logic. * diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php index 98d08bac7d82c278855862814ecf958eb41bf7f3..f651742014009240e5e059ea687fcb71dde1f67d 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php @@ -163,7 +163,7 @@ public function id() { /** * Implements Drupal\Core\Entity\EntityInterface::label(). */ - public function label($langcode = NULL) { + public function label() { return $this->get('title')->value; } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php index f1b2a09cd50b08866abf10a1a809162b1059844b..e48e45d9515a454ecb5d9907c260821ba77b8764 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php @@ -42,7 +42,7 @@ public function id() { /** * Implements Drupal\Core\Entity\EntityInterface::label(). */ - public function label($langcode = NULL) { + public function label() { return $this->get('title')->value; } diff --git a/core/modules/block/lib/Drupal/block/Entity/Block.php b/core/modules/block/lib/Drupal/block/Entity/Block.php index 89dde8d7166a9dedd4bf63dfab58204fde98bde5..926ef07bc92d5a4925a77180ec673d70d57a2ec5 100644 --- a/core/modules/block/lib/Drupal/block/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Entity/Block.php @@ -117,7 +117,7 @@ public function getPlugin() { /** * Overrides \Drupal\Core\Entity\Entity::label(); */ - public function label($langcode = NULL) { + public function label() { $settings = $this->get('settings'); if ($settings['label']) { return $settings['label']; diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index d552d1d42a40b865c3194cbb9d5edf2f08b57aa2..4547ea7ab5dac0ecd065b6212e447924d16816b2 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -382,13 +382,11 @@ function entity_test_entity_test_insert($entity) { * * @param $entity * The entity object. - * @param $langcocde - * (optional) The langcode. * * @return * The label of the entity prefixed with "label callback". */ -function entity_test_label_callback($entity, $langcode = NULL) { +function entity_test_label_callback($entity) { return 'label callback ' . $entity->name->value; } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php index 1193cd50551f268e3517dbe67904d49811250de6..9798c4f0d0922cce301571c94b6701cdf2983df4 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php @@ -107,7 +107,7 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr /** * Overrides Drupal\entity\Entity::label(). */ - public function label($langcode = NULL) { + public function label() { $info = $this->entityInfo(); if (!isset($langcode)) { $langcode = $this->activeLangcode; diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index 35af76a8b11bac3a0b4d3b76a4c5b0f0a223761d..2954df5a9e3e3f9ed914013f113b5f6cb6a40e5a 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -445,6 +445,8 @@ public static function baseFieldDefinitions($entity_type) { ->setLabel(t('Preferred language code')) ->setDescription(t("The user's preferred language code for viewing administration pages.")); + // The name should not vary per language. The username is the visual + // identifier for a user and needs to be consistent in all languages. $fields['name'] = FieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t('The name of this user.')) diff --git a/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php index b91b6bddd4abf3e83bc7bec1266ba26f883e7b07..f96fbd030082a1b3470122ff31d457f8b8c28f71 100644 --- a/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -147,7 +147,7 @@ public function createDuplicate() { * * When a certain view doesn't have a label return the ID. */ - public function label($langcode = NULL) { + public function label() { if (!$label = $this->get('label')) { $label = $this->id(); } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index ed94fc7260322cc48b2cbde67f741bf8c224f292..ea6448c40cd946c1158d1bf92b7ae30406f2513a 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -897,8 +897,8 @@ public function uri() { /** * Implements \Drupal\Core\Entity\EntityInterface::label(). */ - public function label($langcode = NULL) { - return $this->storage->label($langcode); + public function label() { + return $this->storage->label(); } /**