This project is not covered by Drupal’s security advisory policy.
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.
}
Supporting organizations:
Project information
Seeking co-maintainer(s)
Maintainers are looking for help reviewing issues.- Project categories: Developer tools, Import and export, Site structure
2 sites report using this module
- Created by dixon_ on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.

