You are here

function range_field_views_data_base in Range 8

Helper function. Returns misc data for a given field.

This function returns misc field data, that is required by various Views plugins. Data includes field label and field additional fields.

Parameters

\Drupal\field\FieldStorageConfigInterface $field_storage: The field storage config entity.

Return value

array Field data array containing:

  • Field label.
  • Field data table name.
  • Field data revision archive table name.
  • Array of field additional fields keyed by column name.
2 calls to range_field_views_data_base()
range_field_views_data_argument in ./range.views.inc
Provides range views argument data.
range_field_views_data_filter in ./range.views.inc
Provides range views filter data.

File

./range.views.inc, line 40
Provides views data for the range module.

Code

function range_field_views_data_base(FieldStorageConfigInterface $field_storage) {
  $field_name = $field_storage
    ->getName();

  // Check if the entity type supports revisions.
  $entity_manager = \Drupal::entityTypeManager();
  $entity_type_id = $field_storage
    ->getTargetEntityTypeId();
  $entity_type = $entity_manager
    ->getDefinition($entity_type_id);
  $supports_revisions = $entity_type
    ->hasKey('revision') && $entity_type
    ->getRevisionTable();

  // Get most used field label.
  $label = views_entity_field_label($entity_type_id, $field_name)[0];

  // Get additional fields.
  $storage = _views_field_get_entity_type_storage($field_storage);
  $table_mapping = $storage
    ->getTableMapping();
  $add_field_names = [
    'delta',
    'langcode',
    'bundle',
  ];
  $add_fields = array_combine($add_field_names, $add_field_names);
  foreach (array_keys($field_storage
    ->getColumns()) as $column) {
    $add_fields[$column] = $table_mapping
      ->getFieldColumnName($field_storage, $column);
  }
  return [
    $label,
    $table_mapping
      ->getDedicatedDataTableName($field_storage),
    $supports_revisions ? $table_mapping
      ->getDedicatedRevisionTableName($field_storage) : NULL,
    $add_fields,
  ];
}