function ctools_field_label

Returns the label of a certain field.

Cribbed from Views.

2 calls to ctools_field_label()
ctools_entity_field_content_type_admin_title in plugins/content_types/entity_context/entity_field.inc
Returns the administrative title for a type.
ctools_entity_from_field_get_children in plugins/relationships/entity_from_field.inc

File

includes/fields.inc, line 159

Code

function ctools_field_label($field_name) {
    $label_counter = array();
    // Count the amount of instances per label per field.
    $instances = field_info_instances();
    foreach ($instances as $entity_type) {
        foreach ($entity_type as $bundle) {
            if (isset($bundle[$field_name])) {
                $label_counter[$bundle[$field_name]['label']] = isset($label_counter[$bundle[$field_name]['label']]) ? ++$label_counter[$bundle[$field_name]['label']] : 1;
            }
        }
    }
    if (empty($label_counter)) {
        return $field_name;
    }
    // Sort the field lables by it most used label and return the most used one.
    arsort($label_counter);
    $label_counter = array_keys($label_counter);
    return $label_counter[0];
}