diff --git a/core/core.services.yml b/core/core.services.yml index 05067ab59830d0c5bf9a1da472d1999022b22c04..7780dfd0c290aeeaa92f47d80b2ad35af6268266 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1790,13 +1790,3 @@ services: pager.parameters: class: Drupal\Core\Pager\PagerParameters arguments: ['@request_stack'] - select_extender_factory.pager: - class: Drupal\Core\Database\Query\PagerSelectExtenderFactory - arguments: ['@pager.manager'] - tags: - - { name: backend_overridable } - select_extender_factory.table_sort: - class: Drupal\Core\Database\Query\TableSortExtenderFactory - arguments: ['@request_stack'] - tags: - - { name: backend_overridable } diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 04ef0c3170dc26defcf56b7bfbd47a5497d330db..da910131e11bc96eccb84cb47430c18de13b37ea 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -2180,14 +2180,8 @@ public function getProvider(): string { * * @throws \Drupal\Core\DependencyInjection\ContainerNotInitializedException * If the container has not been initialized yet. - * - * @deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use - * dependency injection instead. - * - * @see https://www.drupal.org/node/3218001 */ public function getPagerManager(): PagerManagerInterface { - @trigger_error(__METHOD__ . '() is deprecated in drupal:9.4.0 and will be required in drupal:10.0.0. Use dependency injection instead. See https://www.drupal.org/node/3218001', E_USER_DEPRECATED); return \Drupal::service('pager.manager'); } diff --git a/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php b/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php index 02020cd52b04393e1e4a0001e469271336ddfdf0..1a53ec860143e8b3836f4d08830da7b29aa3111b 100644 --- a/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php +++ b/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php @@ -3,7 +3,6 @@ namespace Drupal\Core\Database\Query; use Drupal\Core\Database\Connection; -use Drupal\Core\Pager\PagerManagerInterface; /** * Query extender for pager queries. @@ -17,13 +16,6 @@ */ class PagerSelectExtender extends SelectExtender { - /** - * The pager manager service. - * - * @var \Drupal\Core\Pager\PagerManagerInterface - */ - protected $pagerManager; - /** * The highest element we've autogenerated so far. * @@ -64,16 +56,9 @@ class PagerSelectExtender extends SelectExtender { * Select query object. * @param \Drupal\Core\Database\Connection $connection * Database connection object. - * @param \Drupal\Core\Pager\PagerManagerInterface $pager_manager - * The pager manager service. */ - public function __construct(SelectInterface $query, Connection $connection, PagerManagerInterface $pager_manager = NULL) { - if (is_null($pager_manager)) { - @trigger_error('Calling ' . __METHOD__ . ' without the $pager_manager argument is deprecated in drupal:9.4.0 and will be required in drupal:10.0.0. Use the relevant service to instantiate extenders. See https://www.drupal.org/node/3218001', E_USER_DEPRECATED); - $pager_manager = \Drupal::service('pager.manager'); - } + public function __construct(SelectInterface $query, Connection $connection) { parent::__construct($query, $connection); - $this->pagerManager = $pager_manager; // Add pager tag. Do this here to ensure that it is always added before // preExecute() is called. @@ -101,7 +86,7 @@ public function execute() { $this->ensureElement(); $total_items = $this->getCountQuery()->execute()->fetchField(); - $pager = $this->pagerManager->createPager($total_items, $this->limit, $this->element); + $pager = $this->connection->getPagerManager()->createPager($total_items, $this->limit, $this->element); $this->range($pager->getCurrentPage() * $this->limit, $this->limit); // Now that we've added our pager-based range instructions, run the query normally. @@ -116,7 +101,7 @@ public function execute() { */ protected function ensureElement() { if (!isset($this->element)) { - $this->element($this->pagerManager->getMaxPagerElementId() + 1); + $this->element($this->connection->getPagerManager()->getMaxPagerElementId() + 1); } } @@ -184,7 +169,7 @@ public function limit($limit = 10) { */ public function element($element) { $this->element = $element; - $this->pagerManager->reservePagerElementId($this->element); + $this->connection->getPagerManager()->reservePagerElementId($this->element); return $this; } diff --git a/core/lib/Drupal/Core/Database/Query/PagerSelectExtenderFactory.php b/core/lib/Drupal/Core/Database/Query/PagerSelectExtenderFactory.php deleted file mode 100644 index 4c19da9024ceb029ec2523d788f4e5767f7976f2..0000000000000000000000000000000000000000 --- a/core/lib/Drupal/Core/Database/Query/PagerSelectExtenderFactory.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -namespace Drupal\Core\Database\Query; - -use Drupal\Core\Database\Connection; -use Drupal\Core\Pager\PagerManagerInterface; - -/** - * Select extender factory for pager queries. - */ -class PagerSelectExtenderFactory { - - /** - * The pager manager service. - * - * @var \Drupal\Core\Pager\PagerManagerInterface - */ - protected $pagerManager; - - /** - * Constructs a PagerSelectExtenderFactory object. - * - * @param \Drupal\Core\Pager\PagerManagerInterface $pager_manager - * The pager manager service. - */ - public function __construct(PagerManagerInterface $pager_manager) { - $this->pagerManager = $pager_manager; - } - - /** - * Returns a query extender for pager queries. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * Select query object. - * @param \Drupal\Core\Database\Connection $connection - * Database connection object. - * - * @return \Drupal\Core\Database\Query\PagerSelectExtender - * A query extender for pager queries. - */ - public function get(SelectInterface $query, Connection $connection): PagerSelectExtender { - return new PagerSelectExtender($query, $connection, $this->pagerManager); - } - -} diff --git a/core/lib/Drupal/Core/Database/Query/Select.php b/core/lib/Drupal/Core/Database/Query/Select.php index 6001aa82f9ad1c5c772a5ca3e41063d099a06247..ac7bdd4e6f932717865ba41c1012aaa6e6694bac 100644 --- a/core/lib/Drupal/Core/Database/Query/Select.php +++ b/core/lib/Drupal/Core/Database/Query/Select.php @@ -320,18 +320,7 @@ public function havingCompile(Connection $connection) { * {@inheritdoc} */ public function extend($extender_name) { - // @todo remove the BC layer in Drupal 10. - // @see https://www.drupal.org/project/drupal/issues/3260284 $parts = explode('\\', $extender_name); - - if (count($parts) === 1) { - return \Drupal::service('select_extender_factory.' . $extender_name)->get($this, $this->connection); - } - - // BC layer. - // @todo remove in Drupal 10. - // @see https://www.drupal.org/project/drupal/issues/3260284 - @trigger_error("Passing '$extender_name' as a fully qualified class name to " . __METHOD__ . '() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Pass the appropriate suffix for a \'select_extender_factory\' service instead. See https://www.drupal.org/node/3218001', E_USER_DEPRECATED); $class = end($parts); $driver_class = $this->connection->getDriverClass($class); if ($driver_class !== $class) { diff --git a/core/lib/Drupal/Core/Database/Query/SelectExtender.php b/core/lib/Drupal/Core/Database/Query/SelectExtender.php index f5b3721e38f5312520afc108f397f21333fe9d2a..0681813f04cc47821b225e41282ef1322324fcb0 100644 --- a/core/lib/Drupal/Core/Database/Query/SelectExtender.php +++ b/core/lib/Drupal/Core/Database/Query/SelectExtender.php @@ -221,18 +221,7 @@ public function extend($extender_name) { // We cannot call $this->query->extend(), because with multiple extenders // you will replace all the earlier extenders with the last extender, // instead of creating list of objects that extend each other. - // @todo remove the BC layer in Drupal 10. - // @see https://www.drupal.org/project/drupal/issues/3260284 $parts = explode('\\', $extender_name); - - if (count($parts) === 1) { - return \Drupal::service('select_extender_factory.' . $extender_name)->get($this, $this->connection); - } - - // BC layer. - // @todo remove in Drupal 10. - // @see https://www.drupal.org/project/drupal/issues/3260284 - @trigger_error("Passing '$extender_name' as a fully qualified class name to " . __METHOD__ . '() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Pass the appropriate suffix for a \'select_extender_factory\' service instead. See https://www.drupal.org/node/3218001', E_USER_DEPRECATED); $class = end($parts); $driver_class = $this->connection->getDriverClass($class); if ($driver_class !== $class) { diff --git a/core/lib/Drupal/Core/Database/Query/TableSortExtender.php b/core/lib/Drupal/Core/Database/Query/TableSortExtender.php index 3b9a00de40b7002e576746c15c7d85a3290ca509..60da1b864acecf9a0cc5c8541aed52c61e549351 100644 --- a/core/lib/Drupal/Core/Database/Query/TableSortExtender.php +++ b/core/lib/Drupal/Core/Database/Query/TableSortExtender.php @@ -4,7 +4,6 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Utility\TableSort; -use Symfony\Component\HttpFoundation\RequestStack; /** * Query extender class for tablesort queries. @@ -12,29 +11,10 @@ class TableSortExtender extends SelectExtender { /** - * The request stack. - * - * @var \Symfony\Component\HttpFoundation\RequestStack - */ - protected $requestStack; - - /** - * Constructs a TableSortExtender object. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * Select query object. - * @param \Drupal\Core\Database\Connection $connection - * Database connection object. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. + * {@inheritdoc} */ - public function __construct(SelectInterface $query, Connection $connection, RequestStack $request_stack = NULL) { - if (is_null($request_stack)) { - @trigger_error('Calling ' . __METHOD__ . ' without the $request_stack argument is deprecated in drupal:9.4.0 and will be required in drupal:10.0.0. Use the relevant service to instantiate extenders. See https://www.drupal.org/node/3218001', E_USER_DEPRECATED); - $request_stack = \Drupal::service('request_stack'); - } + public function __construct(SelectInterface $query, Connection $connection) { parent::__construct($query, $connection); - $this->requestStack = $request_stack; // Add convenience tag to mark that this is an extended query. We have to // do this in the constructor to ensure that it is set before preExecute() @@ -54,7 +34,7 @@ public function __construct(SelectInterface $query, Connection $connection, Requ * @see table.html.twig */ public function orderByHeader(array $header) { - $context = TableSort::getContextFromRequest($header, $this->requestStack->getCurrentRequest()); + $context = TableSort::getContextFromRequest($header, \Drupal::request()); if (!empty($context['sql'])) { // Based on code from \Drupal\Core\Database\Connection::escapeTable(), // but this can also contain a dot. diff --git a/core/lib/Drupal/Core/Database/Query/TableSortExtenderFactory.php b/core/lib/Drupal/Core/Database/Query/TableSortExtenderFactory.php deleted file mode 100644 index 5eee532103b46a8a4ebaed6dc917c6f4b0827982..0000000000000000000000000000000000000000 --- a/core/lib/Drupal/Core/Database/Query/TableSortExtenderFactory.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -namespace Drupal\Core\Database\Query; - -use Drupal\Core\Database\Connection; -use Symfony\Component\HttpFoundation\RequestStack; - -/** - * Select extender factory for tablesort queries. - */ -class TableSortExtenderFactory { - - /** - * The request stack. - * - * @var \Symfony\Component\HttpFoundation\RequestStack - */ - protected $requestStack; - - /** - * Constructs a TableSortExtenderFactory object. - * - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. - */ - public function __construct(RequestStack $request_stack) { - $this->requestStack = $request_stack; - } - - /** - * Returns a query extender for tablesort queries. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * Select query object. - * @param \Drupal\Core\Database\Connection $connection - * Database connection object. - * - * @return \Drupal\Core\Database\Query\TableSortExtender - * A query extender for tablesort queries. - */ - public function get(SelectInterface $query, Connection $connection): TableSortExtender { - return new TableSortExtender($query, $connection, $this->requestStack); - } - -} diff --git a/core/lib/Drupal/Core/Pager/PagerManagerInterface.php b/core/lib/Drupal/Core/Pager/PagerManagerInterface.php index c4e31f5bffc9a3f149011734be9a613975b0f92e..113fcb84302548112679095e41e53f1f17d99e09 100644 --- a/core/lib/Drupal/Core/Pager/PagerManagerInterface.php +++ b/core/lib/Drupal/Core/Pager/PagerManagerInterface.php @@ -29,11 +29,11 @@ interface PagerManagerInterface { * If the items being displayed result from a database query performed using * Drupal's database API, and if you have control over the construction of the * database query, you do not need to call this function directly; instead, - * you can extend the query object with the 'pager' select query extender + * you can extend the query object with the 'PagerSelectExtender' extender * before executing it. For example: * @code * $query = $connection->select('some_table') - * ->extend('pager'); + * ->extend(PagerSelectExtender::class); * @endcode * * However, if you are using a different method for generating the items to be diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php index 4a8122f9c1e90737f9e3a668e608dfaba3ec6e47..6bf70252189c5dc7f1f7e2eaa77e894de16fd86f 100644 --- a/core/modules/comment/src/CommentStorage.php +++ b/core/modules/comment/src/CommentStorage.php @@ -5,6 +5,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -287,7 +288,7 @@ public function loadThread(EntityInterface $entity, $field_name, $mode, $comment ->addMetaData('field_name', $field_name); if ($comments_per_page) { - $query = $query->extend('pager') + $query = $query->extend(PagerSelectExtender::class) ->limit($comments_per_page); if ($pager_id) { $query->element($pager_id); diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index 195f17b6615b283ffc1ab134d97d0508e52d6d5d..b52ed5015a2dddf44a0241ba566ddc3690b03da3 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -9,6 +9,8 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; +use Drupal\Core\Database\Query\TableSortExtender; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBuilderInterface; @@ -151,8 +153,8 @@ public function overview(Request $request) { ]; $query = $this->database->select('watchdog', 'w') - ->extend('pager') - ->extend('table_sort'); + ->extend(PagerSelectExtender::class) + ->extend(TableSortExtender::class); $query->fields('w', [ 'wid', 'uid', @@ -421,8 +423,8 @@ public function topLogMessages($type) { $count_query->condition('type', $type); $query = $this->database->select('watchdog', 'w') - ->extend('pager') - ->extend('table_sort'); + ->extend(PagerSelectExtender::class) + ->extend(TableSortExtender::class); $query->addExpression('COUNT([wid])', 'count'); $query = $query ->fields('w', ['message', 'variables']) diff --git a/core/modules/forum/src/ForumManager.php b/core/modules/forum/src/ForumManager.php index 29277de9e4e5f9e911acc6f8b4813818e9ae5918..3e9a16e9a6cc07478d6f9a1434c42187b4361113 100644 --- a/core/modules/forum/src/ForumManager.php +++ b/core/modules/forum/src/ForumManager.php @@ -4,6 +4,8 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; +use Drupal\Core\Database\Query\TableSortExtender; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -160,8 +162,8 @@ public function getTopics($tid, AccountInterface $account) { } $query = $this->connection->select('forum_index', 'f') - ->extend('pager') - ->extend('table_sort'); + ->extend(PagerSelectExtender::class) + ->extend(TableSortExtender::class); $query->fields('f'); $query ->condition('f.tid', $tid) @@ -187,7 +189,7 @@ public function getTopics($tid, AccountInterface $account) { $nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids); $query = $this->connection->select('node_field_data', 'n') - ->extend('table_sort'); + ->extend(TableSortExtender::class); $query->fields('n', ['nid']); $query->join('comment_entity_statistics', 'ces', "[n].[nid] = [ces].[entity_id] AND [ces].[field_name] = 'comment_forum' AND [ces].[entity_type] = 'node'"); diff --git a/core/modules/help_topics/src/Plugin/Search/HelpSearch.php b/core/modules/help_topics/src/Plugin/Search/HelpSearch.php index c69d531cb05641bf1c1c865fc382bb19c2e27da1..49b0038d0d1e42d0268a2734815a8d59ba4c43f0 100644 --- a/core/modules/help_topics/src/Plugin/Search/HelpSearch.php +++ b/core/modules/help_topics/src/Plugin/Search/HelpSearch.php @@ -6,6 +6,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Config\Config; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Database\StatementInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; @@ -219,8 +220,8 @@ protected function findResults() { ->select('search_index', 'i') // Restrict the search to the current interface language. ->condition('i.langcode', $this->languageManager->getCurrentLanguage()->getId()) - ->extend('search_query') - ->extend('pager'); + ->extend(SearchQuery::class) + ->extend(PagerSelectExtender::class); $query->innerJoin('help_search_items', 'hsi', '[i].[sid] = [hsi].[sid] AND [i].[type] = :type', [':type' => $this->getType()]); if ($denied_permissions) { $query->condition('hsi.permission', $denied_permissions, 'NOT IN'); diff --git a/core/modules/locale/src/StringDatabaseStorage.php b/core/modules/locale/src/StringDatabaseStorage.php index 541b1d69d5171e98e926d4b75f0c52b882cd5d10..74e94fca5d160ee85be61e572144ec962f51f38b 100644 --- a/core/modules/locale/src/StringDatabaseStorage.php +++ b/core/modules/locale/src/StringDatabaseStorage.php @@ -3,6 +3,7 @@ namespace Drupal\locale; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; /** * Defines a class to store localized strings in the database. @@ -442,7 +443,7 @@ protected function dbStringSelect(array $conditions, array $options = []) { } if (!empty($options['pager limit'])) { - $query = $query->extend('pager')->limit($options['pager limit']); + $query = $query->extend(PagerSelectExtender::class)->limit($options['pager limit']); } return $query; diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index 3ab001a4ebc19908d618eced6d08512410f125be..0342c5f01d29c33bba4d00420feeaf332d6155cf 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -7,6 +7,7 @@ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Config\Config; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\StatementInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -261,8 +262,8 @@ protected function findResults() { // Build matching conditions. $query = $this->databaseReplica ->select('search_index', 'i') - ->extend('search_query') - ->extend('pager'); + ->extend(SearchQuery::class) + ->extend(PagerSelectExtender::class); $query->join('node_field_data', 'n', '[n].[nid] = [i].[sid] AND [n].[langcode] = [i].[langcode]'); $query->condition('n.status', 1) ->addTag('node_access') diff --git a/core/modules/search/search.services.yml b/core/modules/search/search.services.yml index 107038260caf10566f728d0be8595a8d1177fd2d..8f6e2a0fcc16b0f730b47f73a8074b26f9895d10 100644 --- a/core/modules/search/search.services.yml +++ b/core/modules/search/search.services.yml @@ -16,15 +16,3 @@ services: search.text_processor: class: Drupal\search\SearchTextProcessor arguments: ['@transliteration', '@config.factory', '@module_handler'] - - select_extender_factory.search_query: - class: Drupal\search\SearchQueryFactory - arguments: ['@config.factory', '@search.text_processor'] - tags: - - { name: backend_overridable } - - select_extender_factory.views_search_query: - class: Drupal\search\ViewsSearchQueryFactory - arguments: ['@config.factory', '@search.text_processor'] - tags: - - { name: backend_overridable } diff --git a/core/modules/search/src/Plugin/views/argument/Search.php b/core/modules/search/src/Plugin/views/argument/Search.php index 02dee62a847265bda43f7546a34906d8043832fb..ab61880e144b41da589aecbea623be45f1132760 100644 --- a/core/modules/search/src/Plugin/views/argument/Search.php +++ b/core/modules/search/src/Plugin/views/argument/Search.php @@ -2,6 +2,7 @@ namespace Drupal\search\Plugin\views\argument; +use Drupal\search\ViewsSearchQuery; use Drupal\views\Plugin\views\argument\ArgumentPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; @@ -47,7 +48,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o */ protected function queryParseSearchExpression($input) { if (!isset($this->searchQuery)) { - $this->searchQuery = \Drupal::service('database.replica')->select('search_index', 'i')->extend('views_search_query'); + $this->searchQuery = \Drupal::service('database.replica')->select('search_index', 'i')->extend(ViewsSearchQuery::class); $this->searchQuery->searchExpression($input, $this->searchType); $this->searchQuery->publicParseSearchExpression(); } diff --git a/core/modules/search/src/Plugin/views/filter/Search.php b/core/modules/search/src/Plugin/views/filter/Search.php index 1f5325465139b9094f0a5e12f31525b0cd798168..c0b0d4516b3e9a4e852100c79ec21fba403aee26 100644 --- a/core/modules/search/src/Plugin/views/filter/Search.php +++ b/core/modules/search/src/Plugin/views/filter/Search.php @@ -3,6 +3,7 @@ namespace Drupal\search\Plugin\views\filter; use Drupal\Core\Form\FormStateInterface; +use Drupal\search\ViewsSearchQuery; use Drupal\views\Plugin\views\filter\FilterPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; @@ -119,7 +120,7 @@ public function validateExposed(&$form, FormStateInterface $form_state) { protected function queryParseSearchExpression($input) { if (!isset($this->searchQuery)) { $this->parsed = TRUE; - $this->searchQuery = \Drupal::service('database.replica')->select('search_index', 'i')->extend('views_search_query'); + $this->searchQuery = \Drupal::service('database.replica')->select('search_index', 'i')->extend(ViewsSearchQuery::class); $this->searchQuery->searchExpression($input, $this->searchType); $this->searchQuery->publicParseSearchExpression(); } diff --git a/core/modules/search/src/SearchQuery.php b/core/modules/search/src/SearchQuery.php index aa1ef3bc1e853b925016c20e95be913e8744e65e..6869da434f7128da7e6063deb2beb8d21319b2ff 100644 --- a/core/modules/search/src/SearchQuery.php +++ b/core/modules/search/src/SearchQuery.php @@ -2,8 +2,6 @@ namespace Drupal\search; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\Query\SelectInterface; @@ -75,20 +73,6 @@ class SearchQuery extends SelectExtender { */ const NO_KEYWORD_MATCHES = 8; - /** - * The config factory. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * The search text processor service. - * - * @var \Drupal\search\SearchTextProcessorInterface - */ - protected $searchTextProcessor; - /** * The keywords and advanced search options that are entered by the user. * @@ -202,32 +186,6 @@ class SearchQuery extends SelectExtender { */ protected $multiply = []; - /** - * Constructs a TableSortExtender object. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * Select query object. - * @param \Drupal\Core\Database\Connection $connection - * Database connection object. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. - * @param \Drupal\search\SearchTextProcessorInterface $search_text_processor - * The search text processor service. - */ - public function __construct(SelectInterface $query, Connection $connection, ConfigFactoryInterface $config_factory = NULL, SearchTextProcessorInterface $search_text_processor = NULL) { - if (is_null($config_factory)) { - @trigger_error('Calling ' . __METHOD__ . ' without the $config_factory argument is deprecated in drupal:9.4.0 and will be required in drupal:10.0.0. Use the relevant service to instantiate extenders. See https://www.drupal.org/node/3218001', E_USER_DEPRECATED); - $config_factory = \Drupal::service('config.factory'); - } - if (is_null($search_text_processor)) { - @trigger_error('Calling ' . __METHOD__ . ' without the $search_text_processor argument is deprecated in drupal:9.4.0 and will be required in drupal:10.0.0. Use the relevant service to instantiate extenders. See https://www.drupal.org/node/3218001', E_USER_DEPRECATED); - $search_text_processor = \Drupal::service('search.text_processor'); - } - parent::__construct($query, $connection); - $this->configFactory = $config_factory; - $this->searchTextProcessor = $search_text_processor; - } - /** * Sets the search query expression. * @@ -273,7 +231,9 @@ protected function parseSearchExpression() { // Classify tokens. $in_or = FALSE; - $limit_combinations = $this->configFactory->get('search.settings')->get('and_or_limit'); + $limit_combinations = \Drupal::config('search.settings')->get('and_or_limit'); + /** @var \Drupal\search\SearchTextProcessorInterface $text_processor */ + $text_processor = \Drupal::service('search.text_processor'); // The first search expression does not count as AND. $and_count = -1; $or_count = 0; @@ -296,7 +256,7 @@ protected function parseSearchExpression() { // Simplify keyword according to indexing rules and external // preprocessors. Use same process as during search indexing, so it // will match search index. - $words = $this->searchTextProcessor->analyze($match[2]); + $words = $text_processor->analyze($match[2]); // Re-explode in case simplification added more words, except when // matching a phrase. $words = $phrase ? [$words] : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY); @@ -404,7 +364,7 @@ protected function parseWord($word) { $split = explode(' ', $word); foreach ($split as $s) { $num = is_numeric($s); - if ($num || mb_strlen($s) >= $this->configFactory->get('search.settings')->get('index.minimum_word_size')) { + if ($num || mb_strlen($s) >= \Drupal::config('search.settings')->get('index.minimum_word_size')) { if (!isset($this->words[$s])) { $this->words[$s] = $s; $num_new_scores++; diff --git a/core/modules/search/src/SearchQueryFactory.php b/core/modules/search/src/SearchQueryFactory.php deleted file mode 100644 index de5a7a756eeb1ce55595efc6771647b0c9bc17fa..0000000000000000000000000000000000000000 --- a/core/modules/search/src/SearchQueryFactory.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -namespace Drupal\search; - -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Database\Connection; -use Drupal\Core\Database\Query\SelectInterface; - -/** - * Select extender factory for search queries. - */ -class SearchQueryFactory { - - /** - * The config factory. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * The search text processor service. - * - * @var \Drupal\search\SearchTextProcessorInterface - */ - protected $searchTextProcessor; - - /** - * Constructs a SearchQueryFactory object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. - * @param \Drupal\search\SearchTextProcessorInterface $search_text_processor - * The search text processor service. - */ - public function __construct(ConfigFactoryInterface $config_factory, SearchTextProcessorInterface $search_text_processor) { - $this->configFactory = $config_factory; - $this->searchTextProcessor = $search_text_processor; - } - - /** - * Returns a query extender for search queries. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * Select query object. - * @param \Drupal\Core\Database\Connection $connection - * Database connection object. - * - * @return Drupal\search\SearchQuery - * A query extender for search queries. - */ - public function get(SelectInterface $query, Connection $connection): SearchQuery { - return new SearchQuery($query, $connection, $this->configFactory, $this->searchTextProcessor); - } - -} diff --git a/core/modules/search/src/ViewsSearchQueryFactory.php b/core/modules/search/src/ViewsSearchQueryFactory.php deleted file mode 100644 index 09091c8eb780275c241b3be14e70d06a818bf420..0000000000000000000000000000000000000000 --- a/core/modules/search/src/ViewsSearchQueryFactory.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -namespace Drupal\search; - -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Database\Connection; -use Drupal\Core\Database\Query\SelectInterface; - -/** - * Select extender factory for views search queries. - */ -class ViewsSearchQueryFactory { - - /** - * The config factory. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * The search text processor service. - * - * @var \Drupal\search\SearchTextProcessorInterface - */ - protected $searchTextProcessor; - - /** - * Constructs a ViewsSearchQueryFactory object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. - * @param \Drupal\search\SearchTextProcessorInterface $search_text_processor - * The search text processor service. - */ - public function __construct(ConfigFactoryInterface $config_factory, SearchTextProcessorInterface $search_text_processor) { - $this->configFactory = $config_factory; - $this->searchTextProcessor = $search_text_processor; - } - - /** - * Returns a query extender for views search queries. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * Select query object. - * @param \Drupal\Core\Database\Connection $connection - * Database connection object. - * - * @return Drupal\search\ViewsSearchQuery - * A query extender for views search queries. - */ - public function get(SelectInterface $query, Connection $connection): ViewsSearchQuery { - return new ViewsSearchQuery($query, $connection, $this->configFactory, $this->searchTextProcessor); - } - -} diff --git a/core/modules/search/tests/src/Kernel/SearchMatchTest.php b/core/modules/search/tests/src/Kernel/SearchMatchTest.php index 6915d7dc5360aabca00c7c0c472eccbbe93cf9f3..9ec5853f72002176c31663bd8a26bf24814653f2 100644 --- a/core/modules/search/tests/src/Kernel/SearchMatchTest.php +++ b/core/modules/search/tests/src/Kernel/SearchMatchTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\KernelTests\KernelTestBase; use Drupal\search\SearchIndexInterface; +use Drupal\search\SearchQuery; /** * Indexes content and queries it. @@ -164,7 +165,7 @@ public function _testQueries() { $connection = Database::getConnection(); foreach ($queries as $query => $results) { $result = $connection->select('search_index', 'i') - ->extend('search_query') + ->extend(SearchQuery::class) ->searchExpression($query, static::SEARCH_TYPE) ->execute(); @@ -184,7 +185,7 @@ public function _testQueries() { ]; foreach ($queries as $query => $results) { $result = $connection->select('search_index', 'i') - ->extend('search_query') + ->extend(SearchQuery::class) ->searchExpression($query, static::SEARCH_TYPE_2) ->execute(); @@ -207,7 +208,7 @@ public function _testQueries() { ]; foreach ($queries as $query => $results) { $result = $connection->select('search_index', 'i') - ->extend('search_query') + ->extend(SearchQuery::class) ->searchExpression($query, static::SEARCH_TYPE_JPN) ->execute(); diff --git a/core/modules/system/tests/modules/database_test/database_test.services.yml b/core/modules/system/tests/modules/database_test/database_test.services.yml deleted file mode 100644 index 25ee69707aced1f9bf144adaa54ae4f9d0746c6a..0000000000000000000000000000000000000000 --- a/core/modules/system/tests/modules/database_test/database_test.services.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - select_extender_factory.test_extender: - class: Drupal\database_test\TestExtenderFactory - tags: - - { name: backend_overridable } diff --git a/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php b/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php index 7efff27676bc04b209e74daa02bc0ce1ff1a4c48..2364e39fc7df5bf62f695ae5359aba124d0b6c81 100644 --- a/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php +++ b/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php @@ -4,6 +4,8 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; +use Drupal\Core\Database\Query\TableSortExtender; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -71,7 +73,7 @@ public function pagerQueryEven($limit) { // This should result in 2 pages of results. $query = $query - ->extend('pager') + ->extend(PagerSelectExtender::class) ->limit($limit); $names = $query->execute()->fetchCol(); @@ -97,7 +99,7 @@ public function pagerQueryOdd($limit) { // This should result in 4 pages of results. $query = $query - ->extend('pager') + ->extend(PagerSelectExtender::class) ->limit($limit); $names = $query->execute()->fetchCol(); @@ -128,7 +130,7 @@ public function testTablesort() { ->fields('t', ['tid', 'pid', 'task', 'priority']); $query = $query - ->extend('table_sort') + ->extend(TableSortExtender::class) ->orderByHeader($header); // We need all the results at once to check the sort. @@ -160,7 +162,7 @@ public function testTablesortFirst() { ->fields('t', ['tid', 'pid', 'task', 'priority']); $query = $query - ->extend('table_sort') + ->extend(TableSortExtender::class) ->orderByHeader($header) ->orderBy('priority'); diff --git a/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php index 07f538ad3a4ba509f234731adb96d118f24c6873..5570c96f5f687cdedfbf41c3798ccd8cdf98e1ec 100644 --- a/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php +++ b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php @@ -3,6 +3,8 @@ namespace Drupal\database_test\Form; use Drupal\Core\Database\Database; +use Drupal\Core\Database\Query\PagerSelectExtender; +use Drupal\Core\Database\Query\TableSortExtender; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\user\Entity\User; @@ -38,8 +40,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { $count_query->addExpression('COUNT([u].[uid])'); $query = $query - ->extend('pager') - ->extend('table_sort'); + ->extend(PagerSelectExtender::class) + ->extend(TableSortExtender::class); $query ->fields('u', ['uid']) ->limit(50) diff --git a/core/modules/system/tests/modules/database_test/src/TestExtenderFactory.php b/core/modules/system/tests/modules/database_test/src/TestExtenderFactory.php deleted file mode 100644 index d4624d14b88f5d4673191ebc9983dcc59606c058..0000000000000000000000000000000000000000 --- a/core/modules/system/tests/modules/database_test/src/TestExtenderFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -namespace Drupal\database_test; - -use Drupal\Core\Database\Connection; -use Drupal\Core\Database\Query\SelectExtender; -use Drupal\Core\Database\Query\SelectInterface; - -/** - * Test select extender factory. - */ -class TestExtenderFactory { - - /** - * Returns a test query extender. - * - * @param \Drupal\Core\Database\Query\SelectInterface $query - * Select query object. - * @param \Drupal\Core\Database\Connection $connection - * Database connection object. - * - * @return \Drupal\Core\Database\Query\SelectExtender - * A test query extender. - */ - public function get(SelectInterface $query, Connection $connection): SelectExtender { - return new SelectExtender($query, $connection); - } - -} diff --git a/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php b/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php index 7ed5dfa9e729e6ec9f6ff1e22d676d8ec4381508..2cdba660120311cc725e29af5541df4466829b76 100644 --- a/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php +++ b/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php @@ -4,6 +4,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Database\Database; +use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Pager\PagerParametersInterface; use Drupal\Core\Security\TrustedCallbackInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -54,7 +55,7 @@ protected function buildTestTable($element, $limit) { ['data' => 'type'], ['data' => 'timestamp'], ]; - $query = Database::getConnection()->select('watchdog', 'd')->extend('pager')->element($element); + $query = Database::getConnection()->select('watchdog', 'd')->extend(PagerSelectExtender::class)->element($element); $result = $query ->fields('d', ['wid', 'type', 'timestamp']) ->limit($limit) diff --git a/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php b/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php index 8f832d60670c95b3323f37812b5806169557248e..e261f6e9a3fb7841d6921e0c5216d98ee10c9230 100644 --- a/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php +++ b/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php @@ -95,7 +95,7 @@ public function testOddPagerQuery() { public function testInnerPagerQuery() { $connection = Database::getConnection(); $query = $connection->select('test', 't') - ->extend('pager'); + ->extend(PagerSelectExtender::class); $query ->fields('t', ['age']) ->orderBy('age') @@ -118,7 +118,7 @@ public function testInnerPagerQuery() { */ public function testHavingPagerQuery() { $query = Database::getConnection()->select('test', 't') - ->extend('pager'); + ->extend(PagerSelectExtender::class); $query ->fields('t', ['name']) ->orderBy('name') @@ -145,7 +145,7 @@ public function testElementNumbers() { $connection = Database::getConnection(); $query = $connection->select('test', 't') - ->extend('pager') + ->extend(PagerSelectExtender::class) ->element(2) ->fields('t', ['name']) ->orderBy('age') @@ -161,7 +161,7 @@ public function testElementNumbers() { // Setting an element smaller than the previous one should not collide with // the existing pager. $query = $connection->select('test', 't') - ->extend('pager') + ->extend(PagerSelectExtender::class) ->element(1) ->fields('t', ['name']) ->orderBy('age') @@ -175,7 +175,7 @@ public function testElementNumbers() { $this->assertEquals('George', $name, 'Pager query #2 with a specified element ID returned the correct results.'); $query = $connection->select('test', 't') - ->extend('pager') + ->extend(PagerSelectExtender::class) ->fields('t', ['name']) ->orderBy('age') ->limit(1); diff --git a/core/modules/tracker/src/Controller/TrackerController.php b/core/modules/tracker/src/Controller/TrackerController.php index 469f55a071e481279d8dd0358274ea80a47674b0..aeb65755ee4af039455edcc79df03daf06a83f31 100644 --- a/core/modules/tracker/src/Controller/TrackerController.php +++ b/core/modules/tracker/src/Controller/TrackerController.php @@ -7,6 +7,7 @@ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Session\AccountInterface; @@ -130,13 +131,13 @@ public function checkAccess(UserInterface $user, AccountInterface $account) { public function buildContent(UserInterface $user = NULL) { if ($user) { $query = $this->database->select('tracker_user', 't') - ->extend('pager') + ->extend(PagerSelectExtender::class) ->addMetaData('base_table', 'tracker_user') ->condition('t.uid', $user->id()); } else { $query = $this->databaseReplica->select('tracker_node', 't') - ->extend('pager') + ->extend(PagerSelectExtender::class) ->addMetaData('base_table', 'tracker_node'); } diff --git a/core/modules/user/src/Plugin/Search/UserSearch.php b/core/modules/user/src/Plugin/Search/UserSearch.php index eabe843e774ef9ac1596c3d66c6fb717ecd20b73..28f5d0e833638eea605f13f4bc349ee54d9c0273 100644 --- a/core/modules/user/src/Plugin/Search/UserSearch.php +++ b/core/modules/user/src/Plugin/Search/UserSearch.php @@ -4,6 +4,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Database\Connection; +use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Session\AccountInterface; @@ -119,7 +120,7 @@ public function execute() { // Run the query to find matching users. $query = $this->database ->select('users_field_data', 'users') - ->extend('pager'); + ->extend(PagerSelectExtender::class); $query->fields('users', ['uid']); $query->condition('default_langcode', 1); if ($this->currentUser->hasPermission('administer users')) { diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php index 8ea4610b13fe1a68f8fd56c83ccff01f89dedb2a..281f3d4d57c96d589cc05c3b3920f24e3df5acf3 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php @@ -4,6 +4,7 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; +use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Database\RowCountException; use Drupal\user\Entity\User; @@ -210,7 +211,7 @@ public function testCountQuery() { */ public function testHavingCountQuery() { $query = $this->connection->select('test') - ->extend('pager') + ->extend(PagerSelectExtender::class) ->groupBy('age') ->having('[age] + 1 > 0'); $query->addField('test', 'age'); diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectExtenderTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectExtenderTest.php index 914231805a205f090173e1886c9e4d045f3542bc..5a23f9a2500ac3b17e68aad479fb6ecbd94bc77b 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectExtenderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectExtenderTest.php @@ -17,12 +17,7 @@ class SelectExtenderTest extends KernelTestBase { /** - * {@inheritdoc} - */ - protected static $modules = ['database_test', 'search']; - - /** - * Data provider for testExtendLegacy(). + * Data provider for testExtend(). * * @return array * Array of arrays with the following elements: @@ -30,7 +25,7 @@ class SelectExtenderTest extends KernelTestBase { * - The database driver namespace. * - The namespaced class name for which to extend. */ - public function providerExtendLegacy(): array { + public function providerExtend(): array { return [ [ 'Drupal\Core\Database\Query\PagerSelectExtender', @@ -118,14 +113,9 @@ public function providerExtendLegacy(): array { /** * @covers ::extend * @covers \Drupal\Core\Database\Query\SelectExtender::extend - * @dataProvider providerExtendLegacy - * @group legacy + * @dataProvider providerExtend */ - public function testExtendLegacy(string $expected, string $namespace, string $extend): void { - $this->expectDeprecation("Passing '%A' as a fully qualified class name to %A is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Pass the appropriate suffix for a 'select_extender_factory' service instead. See https://www.drupal.org/node/3218001", E_USER_DEPRECATED); - $this->expectDeprecation("Passing '%A' as a fully qualified class name to %A is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Pass the appropriate suffix for a 'select_extender_factory' service instead. See https://www.drupal.org/node/3218001", E_USER_DEPRECATED); - $this->expectDeprecation("Passing '%A' as a fully qualified class name to %A is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Pass the appropriate suffix for a 'select_extender_factory' service instead. See https://www.drupal.org/node/3218001", E_USER_DEPRECATED); - + public function testExtend(string $expected, string $namespace, string $extend): void { $additional_class_loader = new ClassLoader(); $additional_class_loader->addPsr4("Drupal\\corefake\\Driver\\Database\\corefake\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefake"); $additional_class_loader->addPsr4("Drupal\\corefake\\Driver\\Database\\corefakeWithAllCustomClasses\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefakeWithAllCustomClasses"); @@ -147,60 +137,4 @@ public function testExtendLegacy(string $expected, string $namespace, string $ex $this->assertEquals($expected, get_class($select_extender_extended)); } - /** - * Data provider for testExtend(). - * - * @return array - * Array of arrays with the following elements: - * - Expected namespaced class name. - * - The database driver namespace. - * - The suffix of the select_extender_factory.[suffix] service. - */ - public function providerExtend(): array { - return [ - [ - 'Drupal\Core\Database\Query\PagerSelectExtender', - 'Drupal\corefake\Driver\Database\corefake', - 'pager', - ], - [ - 'Drupal\Core\Database\Query\TableSortExtender', - 'Drupal\corefake\Driver\Database\corefake', - 'table_sort', - ], - [ - 'Drupal\search\SearchQuery', - 'Drupal\corefake\Driver\Database\corefake', - 'search_query', - ], - [ - 'Drupal\search\ViewsSearchQuery', - 'Drupal\corefake\Driver\Database\corefake', - 'views_search_query', - ], - ]; - } - - /** - * @covers ::extend - * @covers \Drupal\Core\Database\Query\SelectExtender::extend - * @dataProvider providerExtend - */ - public function testExtend(string $expected, string $namespace, string $extend): void { - $mock_pdo = $this->createMock(StubPDO::class); - $connection = new StubConnection($mock_pdo, ['namespace' => $namespace]); - - // Tests the method \Drupal\Core\Database\Query\Select::extend(). - $select = $connection->select('test')->extend($extend); - $this->assertInstanceOf($expected, $select); - - // Get an instance of the class \Drupal\Core\Database\Query\SelectExtender. - $select_extender = $connection->select('test')->extend('test_extender'); - $this->assertInstanceOf(SelectExtender::class, $select_extender); - - // Tests the method \Drupal\Core\Database\Query\SelectExtender::extend(). - $select_extender_extended = $select_extender->extend($extend); - $this->assertInstanceOf($expected, $select_extender_extended); - } - } diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php index a02105bddb0167b371e1f291dee31cd1056b0f1f..89e98bf4a20415574445da9e178c43b651380184 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php @@ -5,6 +5,7 @@ use Drupal\Core\Database\InvalidQueryException; use Drupal\Core\Database\Database; use Drupal\Core\Database\DatabaseExceptionWrapper; +use Drupal\Core\Database\Query\SelectExtender; /** * Tests the Select query builder. @@ -280,7 +281,7 @@ public function testAlwaysFalseCondition() { */ public function testExtenderAlwaysFalseCondition() { $names = $this->connection->select('test', 'test') - ->extend('test_extender') + ->extend(SelectExtender::class) ->fields('test', ['name']) ->condition('age', 27) ->execute()->fetchCol(); @@ -289,7 +290,7 @@ public function testExtenderAlwaysFalseCondition() { $this->assertSame($names[0], 'George'); $names = $this->connection->select('test', 'test') - ->extend('test_extender') + ->extend(SelectExtender::class) ->fields('test', ['name']) ->condition('age', 27) ->alwaysFalse() diff --git a/core/tests/Drupal/KernelTests/Core/Database/TaggingTest.php b/core/tests/Drupal/KernelTests/Core/Database/TaggingTest.php index 51b0e1a1eeccc320e17afda1f0b975cdb203f223..3a9ea2c7e6e0505f50cc3b9885ec70ee073e12e1 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/TaggingTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/TaggingTest.php @@ -2,6 +2,8 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Core\Database\Query\SelectExtender; + /** * Tests the tagging capabilities of the Select builder. * @@ -60,7 +62,7 @@ public function testHasAnyTag() { */ public function testExtenderHasTag() { $query = $this->connection->select('test') - ->extend('test_extender'); + ->extend(SelectExtender::class); $query->addField('test', 'name'); $query->addField('test', 'age', 'age'); @@ -75,7 +77,7 @@ public function testExtenderHasTag() { */ public function testExtenderHasAllTags() { $query = $this->connection->select('test') - ->extend('test_extender'); + ->extend(SelectExtender::class); $query->addField('test', 'name'); $query->addField('test', 'age', 'age'); @@ -91,7 +93,7 @@ public function testExtenderHasAllTags() { */ public function testExtenderHasAnyTag() { $query = $this->connection->select('test') - ->extend('test_extender'); + ->extend(SelectExtender::class); $query->addField('test', 'name'); $query->addField('test', 'age', 'age');