function entity_label

entity_label($entity_type, $entity)

Returns the label of an entity.

See the 'label callback' component of the hook_entity_info() return value for more information.

Parameters

$entity_type: The entity type; e.g., 'node' or 'user'.

$entity: The entity for which to generate the label.

Return value

The entity label, or FALSE if not found.

File

includes/common.inc, line 8182
Common functions that many Drupal modules will need to reference.

Code

function entity_label($entity_type, $entity) {
  $label = FALSE;
  $info = entity_get_info($entity_type);
  if (isset($info['label callback']) && function_exists($info['label callback'])) {
    $label = $info['label callback']($entity, $entity_type);
  }
  elseif (!empty($info['entity keys']['label']) && isset($entity->{$info['entity keys']['label']})) {
    $label = $entity->{$info['entity keys']['label']};
  }

  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/includes!common.inc/function/entity_label/7.x