Select query extenders are now managed through backend-overrideable services. The service is factory that creates an instance of the class that extends \Drupal\Core\Database\Query\Select. This class used to do dynamic select queries in the Database API.
Calling a select query extender which is created by backend-overrideable service is also different. Instead of using the select extender class as the parameter, the extender key name is now used. Lets take the 4 by core supported select query extenders as an example:
-
Connection->select('some_table')->extend(PagerSelectExtender::class)
has been changed to:Connection->select('some_table')->extend('pager')
-
Connection->select('some_table')->extend(TableSortExtender::class)
has been changed to:Connection->select('some_table')->extend('table_sort')
-
Connection->select('some_table')->extend(SearchQuery::class)
has been changed to:Connection->select('some_table')->extend('search_query')
-
Connection->select('some_table')->extend(ViewsSearchQuery::class)
has been changed to:Connection->select('some_table')->extend('views_search_query')
To create your own select query extender, please take one of the by core supported query extenders as an example. The "new name key" is only used in the name of the factory service that creates the extender class.
In your module services.yml file
select_extender_factory.your_name_key:
class: Drupal\search\YourNameKeyServiceFactory
arguments: ['@config.factory', '@search.text_processor']
tags:
- { name: backend_overridable }
The class name is free to choose. The arguments are the extra arguments that your extender class needs. The query and connection parameters are default parameters that go to every select query extender class. The added tags is so that other modules and/or database drivers can overrride your factory class with an implementation of their own. The arguments and tags keys are optional and can be removed. The query extender can be used by calling: Connection->select('some_table')->extend('your_name_key')
. The "your_name_key" must be same in the services.yml file and as the parameter value in the method extend()
.
Using the full class name as the parameter value in the method Drupal\Core\Database\Query\Select::extend()
has been deprecated. Also the method Drupal\Core\Database\Connection::getPagerManager()
has been deprecated.
Comments
Moved to 10.0.x
This change is not yet introduced in version: 9.4.0
Changes for issue #3217699 will be targeting 10.0.x
see https://www.drupal.org/project/drupal/issues/3217699#comment-14557360 and following comments for more information
Unpublished on July 19, 2023.
Unpublished on July 19, 2023.