You are here

function field_views_field_label in Views (for Drupal 7) 8.3

Same name and namespace in other branches
  1. 7.3 modules/field.views.inc \field_views_field_label()

Returns the label of a certain field.

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

4 calls to field_views_field_label()
field_views_field_default_views_data in modules/field.views.inc
Default views data implementation for a field.
file_field_views_data_views_data_alter in modules/file.views.inc
Implements hook_field_views_data_views_data_alter().
image_field_views_data_views_data_alter in modules/image.views.inc
Implements hook_field_views_data_views_data_alter().
taxonomy_field_views_data_views_data_alter in modules/taxonomy.views.inc
Implements hook_field_views_data_views_data_alter().

File

modules/field.views.inc, line 65
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 lables 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,
  );
}