Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Content Translation Redirect Module content_translation_redirect crossed 1,000 active installs.

Query

2 sites No security coverage
View on drupal.org

This module provides a service for creating generic condition objects that can be used to build system-specific queries. It allows developers to define conditions independently of how they will be executed, making it easier to integrate with various query builders.

A module which provides a service for creating generic Condition objects.

These objects may be passed to any number of functions capable of building a system-specific query based on the passed Query object. It is up to the function consuming the Condition object(s) to build the actual query.

This module provides query service, which can be used with formfactorykits' UserAutoCompleteKit & NodeAutoCompleteKit objects.

Example

/** @var \Drupal\query\Services\QueryInterface $q */
$q = \Drupal::service('query');
$result = example_get_events([
  $q->condition('type')
    ->isEqualTo('event'),
  $q->condition('published')
    ->is(),
  $q->condition('month')
    ->isBetween(2, 10)
    ->isNotIn([3,5,7]),
]);

Consumer Function Example

/**
 * @param Condition[] $conditions
 * @return array
 */
function example_get_events(array $conditions = []) {
  $query = '';
  foreach ($conditions as $condition) {
    $groupConjunction = $condition->getGroupConjunction();
    $key = $condition->getKey();
    foreach ($condition->getRequirementGroups() as $group) {
      $conjunction = $group->getConjunction();
      foreach ($group->getRequirements() as $requirement) {
        $operator = $requirement->getOperator();
        switch ($operator) {
          case Operator::TYPE_EQUALS:
            $value = $requirement->getValue();
            // TODO: Add `$key == $value` condition to $query.
            break;

          case Operator::TYPE_NOT_EQUALS:
            $value = $requirement->getValue();
            // TODO: Add `$key != $value` condition to $query.
            break;

          case Operator::TYPE_IN:
            $values = $requirement->getValues();
            // TODO: Add `$key IN($values)` condition to $query.
            break;

          default:
            throw new \DomainException(vsprintf('Unsupported operator: %s', [
              $operator,
            ]));
        }
      }

      // TODO: Append $conjunction to $query if necessary.
    }

    // TODO: Append $groupConjunction to $query if necessary.
  }

  // TODO: Execute $query.
}

Activity

Total releases
1
First release
Nov 2025
Latest release
7 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Slowing

Releases

Version Type Release date
2.0.0-beta6 Pre-release Nov 22, 2025