W3cubDocs

/Drupal 8

public function Entity::label

public Entity::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

File

core/lib/Drupal/Core/Entity/Entity.php, line 155

Class

Entity
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

public function label() {
  $label = NULL;
  $entity_type = $this->getEntityType();
  if (($label_callback = $entity_type->getLabelCallback()) && is_callable($label_callback)) {
    $label = call_user_func($label_callback, $this);
  }
  elseif (($label_key = $entity_type->getKey('label')) && isset($this->{$label_key})) {
    $label = $this->{$label_key};
  }
  return $label;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Entity.php/function/Entity::label/8.1.x