class ViewsTestEntityReferenceHooks

Hook implementations for views_test_entity_reference.

Hierarchy

Expanded class hierarchy of ViewsTestEntityReferenceHooks

File

core/modules/views/tests/modules/views_test_entity_reference/src/Hook/ViewsTestEntityReferenceHooks.php, line 12

Namespace

Drupal\views_test_entity_reference\Hook
View source
class ViewsTestEntityReferenceHooks {
    
    /**
     * Implements hook_views_data_alter().
     */
    public function viewsDataAlter(&$data) : void {
        $manager = \Drupal::entityTypeManager();
        $field_config_storage = $manager->getStorage('field_config');
        
        /** @var \Drupal\field\FieldConfigInterface[] $field_configs */
        $field_configs = $field_config_storage->loadByProperties([
            'field_type' => 'entity_reference',
        ]);
        foreach ($field_configs as $field_config) {
            $table_name = $field_config->getTargetEntityTypeId() . '__' . $field_config->getName();
            $column_name = $field_config->getName() . '_target_id';
            if (isset($data[$table_name][$column_name]['filter']['id']) && in_array($data[$table_name][$column_name]['filter']['id'], [
                'numeric',
                'string',
            ])) {
                $data[$table_name][$column_name]['filter']['id'] = 'entity_reference';
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
ViewsTestEntityReferenceHooks::viewsDataAlter public function Implements hook_views_data_alter().

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