You are here

function hook_field_views_data in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/views.api.php \hook_field_views_data()
  2. 10 core/modules/views/views.api.php \hook_field_views_data()

Override the default Views data for a Field API field.

The field module's implementation of hook_views_data() invokes this for each field storage, in the module that defines the field type. It is not invoked in other modules.

If no hook implementation exists, hook_views_data() falls back to views_field_default_views_data().

Parameters

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

Return value

array An array of views data, in the same format as the return value of hook_views_data().

See also

views_views_data()

hook_field_views_data_alter()

hook_field_views_data_views_data_alter()

Related topics

8 functions implement hook_field_views_data()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

core_field_views_data in core/modules/views/views.views.inc
Implements hook_field_views_data().
datetime_field_views_data in core/modules/datetime/datetime.views.inc
Implements hook_field_views_data().
datetime_range_field_views_data in core/modules/datetime_range/datetime_range.views.inc
Implements hook_field_views_data().
file_field_views_data in core/modules/file/file.views.inc
Implements hook_field_views_data().
image_field_views_data in core/modules/image/image.views.inc
Implements hook_field_views_data().

... See full list

1 invocation of hook_field_views_data()
views_views_data in core/modules/views/views.views.inc
Implements hook_views_data().

File

core/modules/views/views.api.php, line 524
Describes hooks and plugins provided by the Views module.

Code

function hook_field_views_data(\Drupal\field\FieldStorageConfigInterface $field_storage) {
  $data = views_field_default_views_data($field_storage);
  foreach ($data as $table_name => $table_data) {

    // Add the relationship only on the target_id field.
    $data[$table_name][$field_storage
      ->getName() . '_target_id']['relationship'] = [
      'id' => 'standard',
      'base' => 'file_managed',
      'base field' => 'target_id',
      'label' => t('image from @field_name', [
        '@field_name' => $field_storage
          ->getName(),
      ]),
    ];
  }
  return $data;
}