Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Query

No security coverage Under active development 3 sites

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.
}

Ask your assistant about Query

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
4
Tracked since
Feb 2023
Latest release
1 week ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
2.0.0-beta7 Pre-release 9–11 Oct 8, 2026
2.0.0-beta6 Pre-release 9–11 Nov 22, 2025
2.0.0-beta5 Pre-release 9–10 Feb 24, 2023
2.0.0-beta4 Pre-release 9–10 Feb 1, 2023