You are here

function image_field_views_data in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/image/image.views.inc \image_field_views_data()

Implements hook_field_views_data().

Views integration for image fields. Adds an image relationship to the default field data.

See also

views_field_default_views_data()

File

core/modules/image/image.views.inc, line 18
Provide views data for image.module.

Code

function image_field_views_data(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',
      'entity type' => 'file',
      'base field' => 'fid',
      'label' => t('image from @field_name', [
        '@field_name' => $field_storage
          ->getName(),
      ]),
    ];
  }
  return $data;
}