function hook_field_views_data_alter

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

Alter the Views data for a single Field API field.

This is called on all modules even if there is no hook_field_views_data() implementation for the field, and therefore may be used to alter the default data that views_field_default_views_data() supplies for the field storage.

Parameters

array $data: The views data for the field storage. This has the same format as the return value of hook_views_data().

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

See also

views_views_data()

hook_field_views_data()

hook_field_views_data_views_data_alter()

Related topics

2 functions implement hook_field_views_data_alter()

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

taxonomy_field_views_data_alter in core/modules/taxonomy/taxonomy.views.inc
Implements hook_field_views_data_alter().
views_test_data_field_views_data_alter in core/modules/views/tests/modules/views_test_data/views_test_data.views_execution.inc
Implements hook_field_views_data_alter().

File

core/modules/views/views.api.php, line 585

Code

function hook_field_views_data_alter(array &$data, FieldStorageConfigInterface $field_storage) {
    $entity_type_id = $field_storage->getTargetEntityTypeId();
    $field_name = $field_storage->getName();
    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type_id;
    $table_mapping = \Drupal::entityTypeManager()->getStorage($entity_type_id)
        ->getTableMapping();
    [
        $label,
    ] = views_entity_field_label($entity_type_id, $field_name);
    $data['file_managed'][$pseudo_field_name]['relationship'] = [
        'title' => t('@entity using @field', [
            '@entity' => $entity_type->getLabel(),
            '@field' => $label,
        ]),
        'help' => t('Relate each @entity with a @field set to the image.', [
            '@entity' => $entity_type->getLabel(),
            '@field' => $label,
        ]),
        'id' => 'entity_reverse',
        'field_name' => $field_name,
        'entity_type' => $entity_type_id,
        'field table' => $table_mapping->getDedicatedDataTableName($field_storage),
        'field field' => $field_name . '_target_id',
        'base' => $entity_type->getBaseTable(),
        'base field' => $entity_type->getKey('id'),
        'label' => $field_name,
        'join_extra' => [
            0 => [
                'field' => 'deleted',
                'value' => 0,
                'numeric' => TRUE,
            ],
        ],
    ];
}

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