From b06d19e34957bd3e719dfcff9e6d180ea95330e5 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 11 Sep 2010 06:03:12 +0000 Subject: #629484 by Amitaibu, fago, et al: Added Add entity 'label' key info (e.g. title on node). --- includes/common.inc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'includes') diff --git a/includes/common.inc b/includes/common.inc index 2785b3f5e..dc4624d6c 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -6911,6 +6911,30 @@ function entity_uri($entity_type, $entity) { return $entity->uri ? $entity->uri : NULL; } +/** + * Returns the label of an entity. + * + * @param $entity_type + * The entity type; e.g. 'node' or 'user'. + * @param $entity + * The entity for which to generate a path. + * + * @return + * A string with the entity label (e.g. node title), or FALSE if not found. + */ +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); + } + elseif (!empty($info['entity keys']['label']) && isset($entity->{$info['entity keys']['label']})) { + $label = $entity->{$info['entity keys']['label']}; + } + + return $label; +} + /** * Helper function for attaching field API validation to entity forms. */ -- cgit v1.2.3