You are here

function field_extractor_field_label in Field Extractor 7

Returns the label of a certain field.

Therefore it looks up in all bundles to find the most used instance.

Stolen from Views (field_views_field_label()).

1 call to field_extractor_field_label()
field_extractor_views_data_alter in views/field_extractor.views.inc
Implements hook_views_data_alter().

File

views/field_extractor.views.inc, line 47
Views integration for the Field Extractor module.

Code

function field_extractor_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 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];
}