From b2a6ece3fb12eeb36c3815f74b722c4f174802e3 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Thu, 2 Jan 2014 22:09:04 -0800 Subject: [PATCH] =?UTF-8?q?Issue=20#2142979=20by=20G=C3=A1bor=20Hojtsy,=20?= =?UTF-8?q?LinL,=20k4v,=20plach:=20Entity=20label=20langcode=20argument=20?= =?UTF-8?q?is=20a=20lie,=20incompatible=20with=20current=20API.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Drupal/Core/Entity/ContentEntityBase.php | 9 +++------ core/lib/Drupal/Core/Entity/Entity.php | 4 ++-- .../lib/Drupal/Core/Entity/EntityInterface.php | 7 +------ .../Drupal/Core/Entity/EntityTypeInterface.php | 18 +++++++++--------- .../lib/Drupal/aggregator/Entity/Feed.php | 2 +- .../lib/Drupal/aggregator/Entity/Item.php | 2 +- .../block/lib/Drupal/block/Entity/Block.php | 2 +- .../modules/entity_test/entity_test.module | 4 +--- .../Drupal/entity_test/Entity/EntityTest.php | 2 +- .../user/lib/Drupal/user/Entity/User.php | 2 ++ .../views/lib/Drupal/views/Entity/View.php | 2 +- .../views_ui/lib/Drupal/views_ui/ViewUI.php | 4 ++-- 12 files changed, 25 insertions(+), 33 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 7c68f0ab458f..d62c4047b57a 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 178fe51d1a54..2e4a7eab6cfb 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 66ed701d5b08..b9f1d5e19945 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 1f9cff312268..4cb05aac17b1 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 98d08bac7d82..f65174201400 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 f1b2a09cd50b..e48e45d9515a 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 89dde8d7166a..926ef07bc92d 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 d552d1d42a40..4547ea7ab5da 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 1193cd50551f..9798c4f0d092 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 35af76a8b11b..2954df5a9e3e 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 b91b6bddd4ab..f96fbd030082 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 ed94fc726032..ea6448c40cd9 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(); } /** -- GitLab