Issue #2142979 by Gábor Hojtsy, LinL, k4v, plach: Entity label langcode argument is a lie, incompatible with current API.
parent
cab1c0f461
commit
b2a6ece3fb
|
@ -945,17 +945,14 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 @@ abstract class Entity implements EntityInterface {
|
|||
/**
|
||||
* {@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 @@ interface EntityInterface extends AccessibleInterface {
|
|||
/**
|
||||
* 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 @@ interface EntityTypeInterface {
|
|||
/**
|
||||
* 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 @@ class Feed extends ContentEntityBase implements FeedInterface {
|
|||
/**
|
||||
* Implements Drupal\Core\Entity\EntityInterface::label().
|
||||
*/
|
||||
public function label($langcode = NULL) {
|
||||
public function label() {
|
||||
return $this->get('title')->value;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class Item extends ContentEntityBase implements ItemInterface {
|
|||
/**
|
||||
* Implements Drupal\Core\Entity\EntityInterface::label().
|
||||
*/
|
||||
public function label($langcode = NULL) {
|
||||
public function label() {
|
||||
return $this->get('title')->value;
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ class Block extends ConfigEntityBase implements BlockInterface {
|
|||
/**
|
||||
* 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 @@ class EntityTest extends ContentEntityBase {
|
|||
/**
|
||||
* 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 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
->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 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
|
|||
*
|
||||
* 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 @@ class ViewUI implements ViewStorageInterface {
|
|||
/**
|
||||
* Implements \Drupal\Core\Entity\EntityInterface::label().
|
||||
*/
|
||||
public function label($langcode = NULL) {
|
||||
return $this->storage->label($langcode);
|
||||
public function label() {
|
||||
return $this->storage->label();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue