diff options
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc index 2785b3f5e..dc4624d6c 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -6912,6 +6912,30 @@ function entity_uri($entity_type, $entity) { } /** + * 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. */ function entity_form_field_validate($entity_type, $form, &$form_state) { |