Commit b2a6ece3 authored by webchick's avatar webchick

Issue #2142979 by Gábor Hojtsy, LinL, k4v, plach: Entity label langcode...

Issue #2142979 by Gábor Hojtsy, LinL, k4v, plach: Entity label langcode argument is a lie, incompatible with current API.
parent cab1c0f4
...@@ -945,17 +945,14 @@ public function __clone() { ...@@ -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; $label = NULL;
$entity_info = $this->entityInfo(); $entity_info = $this->entityInfo();
if (!isset($langcode)) {
$langcode = $this->activeLangcode;
}
// @todo Convert to is_callable() and call_user_func(). // @todo Convert to is_callable() and call_user_func().
if (($label_callback = $entity_info->getLabelCallback()) && function_exists($label_callback)) { 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})) { elseif (($label_key = $entity_info->getKey('label')) && isset($this->{$label_key})) {
$label = $this->{$label_key}->value; $label = $this->{$label_key}->value;
......
...@@ -106,12 +106,12 @@ public function bundle() { ...@@ -106,12 +106,12 @@ public function bundle() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function label($langcode = NULL) { public function label() {
$label = NULL; $label = NULL;
$entity_info = $this->entityInfo(); $entity_info = $this->entityInfo();
// @todo Convert to is_callable() and call_user_func(). // @todo Convert to is_callable() and call_user_func().
if (($label_callback = $entity_info->getLabelCallback()) && function_exists($label_callback)) { 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})) { elseif (($label_key = $entity_info->getKey('label')) && isset($this->{$label_key})) {
$label = $this->{$label_key}; $label = $this->{$label_key};
......
...@@ -89,15 +89,10 @@ public function bundle(); ...@@ -89,15 +89,10 @@ public function bundle();
/** /**
* Returns the label of the entity. * 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 * @return
* The label of the entity, or NULL if there is no label defined. * 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. * Returns the URI elements of the entity.
......
...@@ -371,15 +371,15 @@ public function setLinkTemplate($key, $route_name); ...@@ -371,15 +371,15 @@ public function setLinkTemplate($key, $route_name);
/** /**
* Gets the callback for the label of the entity. * Gets the callback for the label of the entity.
* *
* The function takes an entity and optional langcode argument, and returns * The function takes an entity and returns the label of the entity. Use
* the label of the entity. If langcode is omitted, the entity's default * language() on the entity to get information on the requested language. The
* language is used. The entity label is the main string associated with an * entity label is the main string associated with an entity; for example, the
* entity; for example, the title of a node or the subject of a comment. If * title of a node or the subject of a comment. If there is an entity object
* there is an entity object property that defines the label, use the 'label' * property that defines the label, use the 'label' element of the
* element of the 'entity_keys' return value component to provide this * 'entity_keys' return value component to provide this information (see
* information (see below). If more complex logic is needed to determine the * below). If more complex logic is needed to determine the label of an
* label of an entity, you can instead specify a callback function here, which * entity, you can instead specify a callback function here, which will be
* will be called to determine the entity label. See also the * called to determine the entity label. See also the
* \Drupal\Core\Entity\EntityInterface::label() method, which implements this * \Drupal\Core\Entity\EntityInterface::label() method, which implements this
* logic. * logic.
* *
......
...@@ -163,7 +163,7 @@ public function id() { ...@@ -163,7 +163,7 @@ public function id() {
/** /**
* Implements Drupal\Core\Entity\EntityInterface::label(). * Implements Drupal\Core\Entity\EntityInterface::label().
*/ */
public function label($langcode = NULL) { public function label() {
return $this->get('title')->value; return $this->get('title')->value;
} }
......
...@@ -42,7 +42,7 @@ public function id() { ...@@ -42,7 +42,7 @@ public function id() {
/** /**
* Implements Drupal\Core\Entity\EntityInterface::label(). * Implements Drupal\Core\Entity\EntityInterface::label().
*/ */
public function label($langcode = NULL) { public function label() {
return $this->get('title')->value; return $this->get('title')->value;
} }
......
...@@ -117,7 +117,7 @@ public function getPlugin() { ...@@ -117,7 +117,7 @@ public function getPlugin() {
/** /**
* Overrides \Drupal\Core\Entity\Entity::label(); * Overrides \Drupal\Core\Entity\Entity::label();
*/ */
public function label($langcode = NULL) { public function label() {
$settings = $this->get('settings'); $settings = $this->get('settings');
if ($settings['label']) { if ($settings['label']) {
return $settings['label']; return $settings['label'];
......
...@@ -382,13 +382,11 @@ function entity_test_entity_test_insert($entity) { ...@@ -382,13 +382,11 @@ function entity_test_entity_test_insert($entity) {
* *
* @param $entity * @param $entity
* The entity object. * The entity object.
* @param $langcocde
* (optional) The langcode.
* *
* @return * @return
* The label of the entity prefixed with "label callback". * 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; return 'label callback ' . $entity->name->value;
} }
......
...@@ -107,7 +107,7 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr ...@@ -107,7 +107,7 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr
/** /**
* Overrides Drupal\entity\Entity::label(). * Overrides Drupal\entity\Entity::label().
*/ */
public function label($langcode = NULL) { public function label() {
$info = $this->entityInfo(); $info = $this->entityInfo();
if (!isset($langcode)) { if (!isset($langcode)) {
$langcode = $this->activeLangcode; $langcode = $this->activeLangcode;
......
...@@ -445,6 +445,8 @@ public static function baseFieldDefinitions($entity_type) { ...@@ -445,6 +445,8 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Preferred language code')) ->setLabel(t('Preferred language code'))
->setDescription(t("The user's preferred language code for viewing administration pages.")); ->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') $fields['name'] = FieldDefinition::create('string')
->setLabel(t('Name')) ->setLabel(t('Name'))
->setDescription(t('The name of this user.')) ->setDescription(t('The name of this user.'))
......
...@@ -147,7 +147,7 @@ public function createDuplicate() { ...@@ -147,7 +147,7 @@ public function createDuplicate() {
* *
* When a certain view doesn't have a label return the ID. * 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')) { if (!$label = $this->get('label')) {
$label = $this->id(); $label = $this->id();
} }
......
...@@ -897,8 +897,8 @@ public function uri() { ...@@ -897,8 +897,8 @@ public function uri() {
/** /**
* Implements \Drupal\Core\Entity\EntityInterface::label(). * Implements \Drupal\Core\Entity\EntityInterface::label().
*/ */
public function label($langcode = NULL) { public function label() {
return $this->storage->label($langcode); return $this->storage->label();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment