1 field.views.inc | field_views_field_label($field_name) |
Returns the label of a certain field.
Therefore it looks up in all bundles to find the most used instance.
File
- core/
modules/ field/ views/ field.views.inc, line 64 - Provide Views data and handlers for field.module.
Code
function field_views_field_label($field_name) {
$label_counter = array();
$all_labels = array();
// Count the amount of instances per label per field.
$instances = field_info_instances();
foreach ($instances as $entity_name => $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;
$all_labels[$entity_name][$bundle[$field_name]['label']] = TRUE;
}
}
}
if (empty($label_counter)) {
return array($field_name, $all_labels);
}
// Sort the field labels by it most used label and return the most used one.
arsort($label_counter);
$label_counter = array_keys($label_counter);
return array($label_counter[0], $all_labels);
}