diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index de4ec2e646027a6a295b6a8efd045059098742eb..1b3583fcddffa9424bc14ae1382c924fb2c8b182 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -51003,12 +51003,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/views/tests/modules/views_test_modal/src/Controller/TestController.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Function _views_test_query_access_restrict_by_uuid\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/views/tests/modules/views_test_query_access/views_test_query_access.module', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\views\\\\Functional\\\\DefaultViewsTest\\:\\:addDefaultCommentField\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', diff --git a/core/modules/views/tests/modules/views_test_config/src/Hook/ViewsTestConfigHooks.php b/core/modules/views/tests/modules/views_test_config/src/Hook/ViewsTestConfigHooks.php index bb9cfad5b1b6baa44b94fbaf181f2c3dbb26e15f..e18242dc4c6abf4a860592a3aac629ea7fbd118c 100644 --- a/core/modules/views/tests/modules/views_test_config/src/Hook/ViewsTestConfigHooks.php +++ b/core/modules/views/tests/modules/views_test_config/src/Hook/ViewsTestConfigHooks.php @@ -45,7 +45,7 @@ public function viewsPostRender(ViewExecutable $view, &$output, CachePluginBase */ #[Hook('views_plugins_area_alter')] public function viewsPluginsAreaAlter(array &$definitions) : void { - _views_test_config_disable_broken_handler($definitions, 'area'); + $this->disableBrokenHandler($definitions, 'area'); } /** @@ -53,7 +53,7 @@ public function viewsPluginsAreaAlter(array &$definitions) : void { */ #[Hook('views_plugins_argument_alter')] public function viewsPluginsArgumentAlter(array &$definitions) : void { - _views_test_config_disable_broken_handler($definitions, 'argument'); + $this->disableBrokenHandler($definitions, 'argument'); } /** @@ -61,7 +61,7 @@ public function viewsPluginsArgumentAlter(array &$definitions) : void { */ #[Hook('views_plugins_field_alter')] public function viewsPluginsFieldAlter(array &$definitions) : void { - _views_test_config_disable_broken_handler($definitions, 'field'); + $this->disableBrokenHandler($definitions, 'field'); } /** @@ -69,7 +69,7 @@ public function viewsPluginsFieldAlter(array &$definitions) : void { */ #[Hook('views_plugins_filter_alter')] public function viewsPluginsFilterAlter(array &$definitions) : void { - _views_test_config_disable_broken_handler($definitions, 'filter'); + $this->disableBrokenHandler($definitions, 'filter'); } /** @@ -77,7 +77,7 @@ public function viewsPluginsFilterAlter(array &$definitions) : void { */ #[Hook('views_plugins_relationship_alter')] public function viewsPluginsRelationshipAlter(array &$definitions) : void { - _views_test_config_disable_broken_handler($definitions, 'relationship'); + $this->disableBrokenHandler($definitions, 'relationship'); } /** @@ -85,7 +85,16 @@ public function viewsPluginsRelationshipAlter(array &$definitions) : void { */ #[Hook('views_plugins_sort_alter')] public function viewsPluginsSortAlter(array &$definitions) : void { - _views_test_config_disable_broken_handler($definitions, 'sort'); + $this->disableBrokenHandler($definitions, 'sort'); + } + + /** + * Helper method to remove broken handler. + */ + public function disableBrokenHandler(array &$definitions, string $handler_type): void { + if (in_array($handler_type, \Drupal::state()->get('views_test_config_disable_broken_handler', []))) { + unset($definitions['broken']); + } } } diff --git a/core/modules/views/tests/modules/views_test_config/views_test_config.module b/core/modules/views/tests/modules/views_test_config/views_test_config.module deleted file mode 100644 index 71a25f9b017ac0b5a4e5bf3be40541efe32a03de..0000000000000000000000000000000000000000 --- a/core/modules/views/tests/modules/views_test_config/views_test_config.module +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -/** - * @file - * Contains the "views_test_config" module main functionality. - */ - -declare(strict_types=1); - -function _views_test_config_disable_broken_handler(array &$definitions, string $handler_type): void { - if (in_array($handler_type, \Drupal::state()->get('views_test_config_disable_broken_handler', []))) { - unset($definitions['broken']); - } -} diff --git a/core/modules/views/tests/modules/views_test_query_access/src/Hook/ViewsTestQueryAccessHooks.php b/core/modules/views/tests/modules/views_test_query_access/src/Hook/ViewsTestQueryAccessHooks.php index aa3919caaa51244186ed78245ca5bce77681e96b..a00818bb977b872e7066fd60ea7807db988c0cdc 100644 --- a/core/modules/views/tests/modules/views_test_query_access/src/Hook/ViewsTestQueryAccessHooks.php +++ b/core/modules/views/tests/modules/views_test_query_access/src/Hook/ViewsTestQueryAccessHooks.php @@ -5,6 +5,9 @@ namespace Drupal\views_test_query_access\Hook; use Drupal\Core\Database\Query\AlterableInterface; +use Drupal\Core\Database\Query\SelectInterface; +use Drupal\Core\Entity\Sql\DefaultTableMapping; +use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; use Drupal\Core\Hook\Attribute\Hook; /** @@ -17,7 +20,7 @@ class ViewsTestQueryAccessHooks { */ #[Hook('query_media_access_alter')] public function queryMediaAccessAlter(AlterableInterface $query): void { - _views_test_query_access_restrict_by_uuid($query); + $this->restrictByUuid($query); } /** @@ -25,7 +28,52 @@ public function queryMediaAccessAlter(AlterableInterface $query): void { */ #[Hook('query_block_content_access_alter')] public function queryBlockContentAccessAlter(AlterableInterface $query): void { - _views_test_query_access_restrict_by_uuid($query); + $this->restrictByUuid($query); + } + + /** + * Excludes entities with the 'hidden-ENTITY_TYPE_ID' UUID from a query. + * + * @param \Drupal\Core\Database\Query\AlterableInterface $query + * The Views select query to alter. + */ + public function restrictByUuid(AlterableInterface $query): void { + if (!($query instanceof SelectInterface)) { + return; + } + + /** @var \Drupal\views\ViewExecutable $view */ + $view = $query->getMetaData('view'); + $entity_type = $view->getBaseEntityType(); + + $storage = \Drupal::entityTypeManager()->getStorage($entity_type->id()); + if (!($storage instanceof SqlEntityStorageInterface)) { + return; + } + + $table_mapping = $storage->getTableMapping(); + if (!($table_mapping instanceof DefaultTableMapping)) { + return; + } + + $base_table = $table_mapping->getBaseTable(); + $data_table = $table_mapping->getDataTable(); + + // We are excluding entities by UUID, which means we need to be certain the + // base table is joined in the query. + $tables = $query->getTables(); + if (isset($tables[$data_table]) && !isset($tables[$base_table])) { + $data_table_alias = $tables[$data_table]['alias']; + $id_key = $entity_type->getKey('id'); + $base_table = $query->innerJoin($base_table, NULL, "[$data_table_alias].[$id_key] = [$base_table].[$id_key]"); + } + + // Figure out the column name of the UUID field and add a condition on that. + $base_field_definitions = \Drupal::service('entity_field.manager') + ->getBaseFieldDefinitions($entity_type->id()); + $uuid_key = $entity_type->getKey('uuid'); + $uuid_column_name = $table_mapping->getFieldColumnName($base_field_definitions[$uuid_key], NULL); + $query->condition("$base_table.$uuid_column_name", 'hidden-' . $entity_type->id(), '<>'); } } diff --git a/core/modules/views/tests/modules/views_test_query_access/views_test_query_access.module b/core/modules/views/tests/modules/views_test_query_access/views_test_query_access.module deleted file mode 100644 index ab1a1c11fe94a6a0885719ce4d786ae909d179a2..0000000000000000000000000000000000000000 --- a/core/modules/views/tests/modules/views_test_query_access/views_test_query_access.module +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -/** - * @file - * Module to test entity query access in Views. - */ - -declare(strict_types=1); - -use Drupal\Core\Database\Query\AlterableInterface; -use Drupal\Core\Database\Query\SelectInterface; -use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; -use Drupal\Core\Entity\Sql\DefaultTableMapping; - -/** - * Excludes entities with the 'hidden-ENTITY_TYPE_ID' UUID from a query. - * - * @param \Drupal\Core\Database\Query\AlterableInterface $query - * The Views select query to alter. - */ -function _views_test_query_access_restrict_by_uuid(AlterableInterface $query) { - if (!($query instanceof SelectInterface)) { - return; - } - - /** @var \Drupal\views\ViewExecutable $view */ - $view = $query->getMetaData('view'); - $entity_type = $view->getBaseEntityType(); - - $storage = \Drupal::entityTypeManager()->getStorage($entity_type->id()); - if (!($storage instanceof SqlEntityStorageInterface)) { - return; - } - - $table_mapping = $storage->getTableMapping(); - if (!($table_mapping instanceof DefaultTableMapping)) { - return; - } - - $base_table = $table_mapping->getBaseTable(); - $data_table = $table_mapping->getDataTable(); - - // We are excluding entities by UUID, which means we need to be certain the - // base table is joined in the query. - $tables = $query->getTables(); - if (isset($tables[$data_table]) && !isset($tables[$base_table])) { - $data_table_alias = $tables[$data_table]['alias']; - $id_key = $entity_type->getKey('id'); - $base_table = $query->innerJoin($base_table, NULL, "[$data_table_alias].[$id_key] = [$base_table].[$id_key]"); - } - - // Figure out the column name of the UUID field and add a condition on that. - $base_field_definitions = \Drupal::service('entity_field.manager') - ->getBaseFieldDefinitions($entity_type->id()); - $uuid_key = $entity_type->getKey('uuid'); - $uuid_column_name = $table_mapping->getFieldColumnName($base_field_definitions[$uuid_key], NULL); - $query->condition("$base_table.$uuid_column_name", 'hidden-' . $entity_type->id(), '<>'); -}