function hook_field_views_data

Same name in other branches
  1. 8.9.x core/modules/views/views.api.php \hook_field_views_data()
  2. 10 core/modules/views/views.api.php \hook_field_views_data()
  3. 11.x core/modules/views/views.api.php \hook_field_views_data()

Override the default Views data for a Field API field.

When collecting the views data, views_views_data() invokes this hook for each field storage definition, on the module that provides the field storage definition. If the return value is empty, the result of views_field_default_views_data() is used instead. Then the result is altered by invoking hook_field_views_data_alter() on all 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

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.