function EntityBase::label

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::label()
  2. 10 core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::label()
  3. 11.x core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::label()

Gets the label of the entity.

Return value

string|null The label of the entity, or NULL if there is no label defined.

Overrides EntityInterface::label

3 calls to EntityBase::label()
EntityBase::toLink in core/lib/Drupal/Core/Entity/EntityBase.php
Generates the HTML for a link to this entity.
FieldConfigBase::getLabel in core/lib/Drupal/Core/Field/FieldConfigBase.php
Returns a human readable label.
FilterFormat::preSave in core/modules/filter/src/Entity/FilterFormat.php
Acts on an entity before the presave hook is invoked.
5 methods override EntityBase::label()
Block::label in core/modules/block/src/Entity/Block.php
Gets the label of the entity.
ContentEntityBase::label in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Gets the label of the entity.
Editor::label in core/modules/editor/src/Entity/Editor.php
Gets the label of the entity.
TestSearchPage::label in core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php
Gets the label of the entity.
View::label in core/modules/views/src/Entity/View.php
Gets the label of the entity.

File

core/lib/Drupal/Core/Entity/EntityBase.php, line 166

Class

EntityBase
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

public function label() {
  $label = NULL;
  $entity_type = $this->getEntityType();
  if (($label_callback = $entity_type->get('label_callback')) && is_callable($label_callback)) {
    @trigger_error('Entity type ' . $this->getEntityTypeId() . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794', E_USER_DEPRECATED);
    $label = call_user_func($label_callback, $this);
  }
  elseif (($label_key = $entity_type->getKey('label')) && isset($this->{$label_key})) {
    $label = $this->{$label_key};
  }
  return $label;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.