diff --git a/includes/common.inc b/includes/common.inc index c6303ef..0aa86f6 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -8166,6 +8166,32 @@ function entity_label($entity_type, $entity) { } /** + * Returns the label of a bundle. + * + * @param $input_entity_type + * The entity type; e.g. 'node' or 'user'. + * @param $input_bundle + * The machine name of the bundle for which we want the human-readable label. + * + * @return + * A string with the human-readable name of the bundle, or the machine + * readable name if not specified. + */ +function entity_bundle_label($input_entity_type, $input_bundle) { + $labels = &drupal_static(__FUNCTION__, array()); + + if (empty($labels)) { + foreach (entity_get_info() as $entity_type => $entity_info) { + foreach ($entity_info['bundles'] as $bundle => $bundle_info) { + $labels[$entity_type][$bundle] = !empty($bundle_info['label']) ? $bundle_info['label'] : $bundle; + } + } + } + + return isset($labels[$input_entity_type][$input_bundle]) ? $labels[$input_entity_type][$input_bundle] : $input_bundle; +} + +/** * Returns the language of an entity. * * @param $entity_type