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() {
}
/**
* 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;
......
......@@ -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};
......
......@@ -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.
......
......@@ -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.
*
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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'];
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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.'))
......
......@@ -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();
}
......
......@@ -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();
}
/**
......
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