Skip to content
Snippets Groups Projects

Issue #3347343: Continuation Add Views EntityReference filter to be available for all entity reference fields

Open Issue #3347343: Continuation Add Views EntityReference filter to be available for all entity reference fields
Open Bram Driesen requested to merge issue/drupal-3347343:3347343-11-x into 11.x
Compare and
2 files
+ 31
1
Compare changes
  • Side-by-side
  • Inline
Files
2
 
<?php
 
 
/**
 
* @file
 
* Views data altering to test use of the entity reference plugin.
 
*/
 
 
declare(strict_types=1);
 
 
/**
 
* Implements hook_views_data_alter().
 
*/
 
function views_test_entity_reference_views_data_alter(&$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';
 
}
 
}
 
}
Loading