Change record status: 
Project: 
Introduced in branch: 
10.2.x
Introduced in version: 
10.2.0
Description: 

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:

  1. Connection->select('some_table')->extend(PagerSelectExtender::class) has been changed to: Connection->select('some_table')->extend('pager')
  2. Connection->select('some_table')->extend(TableSortExtender::class) has been changed to: Connection->select('some_table')->extend('table_sort')
  3. Connection->select('some_table')->extend(SearchQuery::class) has been changed to: Connection->select('some_table')->extend('search_query')
  4. 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.

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

akasake’s picture

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

mondrake’s picture

Unpublished on July 19, 2023.