diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index 8bae041..e7d2ed2 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -444,8 +444,8 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co 'field_type' => $field_type, 'field_definition' => $field_definition, ]; - $this->moduleHandler->alter('views_entity_field_data', $views_field, $context); $this->moduleHandler->alter('views_entity_field_data_' . $field_type, $views_field, $context); + $this->moduleHandler->alter('views_entity_field_data', $views_field, $context); return $views_field; } diff --git a/core/modules/views/src/Tests/ViewsHooksTest.php b/core/modules/views/src/Tests/ViewsHooksTest.php index 534df07..305ffb3 100644 --- a/core/modules/views/src/Tests/ViewsHooksTest.php +++ b/core/modules/views/src/Tests/ViewsHooksTest.php @@ -33,6 +33,8 @@ class ViewsHooksTest extends ViewUnitTestBase { protected static $hooks = array ( 'views_data' => 'all', 'views_data_alter' => 'alter', + 'views_entity_field_data_alter' => 'alter', + 'views_entity_field_data_boolean_alter' => 'alter', 'views_query_substitutions' => 'view', 'views_form_substitutions' => 'view', 'views_analyze' => 'view', diff --git a/core/modules/views/tests/modules/views_test_data/views_test_data.views.inc b/core/modules/views/tests/modules/views_test_data/views_test_data.views.inc index ceaa8e9..f70669e 100644 --- a/core/modules/views/tests/modules/views_test_data/views_test_data.views.inc +++ b/core/modules/views/tests/modules/views_test_data/views_test_data.views.inc @@ -34,6 +34,20 @@ function views_test_data_views_data_alter() { } /** + * Implements hook_views_entity_field_data_alter(). + */ +function views_test_data_views_entity_field_data_alter() { + \Drupal::state()->set('views_hook_test_views_entity_field_data_alter', TRUE); +} + +/** + * Implements hook_views_entity_field_data_FIELD_TYPE_alter(). + */ +function views_test_data_views_entity_field_data_boolean_alter() { + \Drupal::state()->set('views_hook_test_views_entity_field_data_boolean_alter', TRUE); +} + +/** * Implements hook_views_analyze(). */ function views_test_data_views_analyze(ViewExecutable $view) { diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index 8368bd9..b461cc0 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -597,10 +597,13 @@ function hook_field_views_data_views_data_alter(array &$data, \Drupal\field\Fiel * * @param array $field_data * The array of views entity base field data. + * @param array $context + * A keyed array containing `table`, `column_name`, `field_type`, and + * `field_definition`. * * @see \Drupal\views\EntityViewsData::mapSingleFieldViewsData */ -function hook_views_entity_field_data_alter(&$field_data, $context) { +function hook_views_entity_field_data_alter(&$field_data, array $context) { $field_data['field']['additional key'] = TRUE; } @@ -609,10 +612,13 @@ function hook_views_entity_field_data_alter(&$field_data, $context) { * * @param array $field_data * The array of views entity base field data. - * + * @param array $context + * A keyed array containing `table`, `column_name`, `field_type`, and + * `field_definition`. + * @see \Drupal\views\EntityViewsData::mapSingleFieldViewsData */ -function hook_views_entity_field_data_boolean_alter(&$field_data, $context) { +function hook_views_entity_field_data_FIELD_TYPE_alter(&$field_data, array $context) { $field_data['field']['additional key'] = TRUE; } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 6fc41fa..3f5f0c8 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -583,6 +583,13 @@ function views_hook_info() { ); } + // Register a field_type alter hook for all field types. + foreach (array_keys(\Drupal::service('plugin.manager.field.field_type')->getDefinitions()) as $type) { + $hooks['views_entity_field_data_' . $type . '_alter'] = array( + 'group' => 'views', + ); + } + $hooks += array_fill_keys(array( 'views_query_substitutions', 'views_form_substitutions', @@ -602,6 +609,10 @@ function views_hook_info() { $hooks['field_views_data_alter'] = array( 'group' => 'views', ); + $hooks['views_entity_field_data_alter'] = array( + 'group' => 'views', + ); + return $hooks; }