public function UserRole::alterQuery in RNG - Events and Registrations 8.2
Same name and namespace in other branches
- 8 src/Plugin/Condition/UserRole.php \Drupal\rng\Plugin\Condition\UserRole::alterQuery()
- 3.x src/Plugin/Condition/UserRole.php \Drupal\rng\Plugin\Condition\UserRole::alterQuery()
Modify a query with condition configuration.
This does not rely on any contexts, only valid configuration.
Parameters
\Drupal\Core\Entity\Query\QueryInterface $query: The query object.
Overrides RNGConditionInterface::alterQuery
File
- src/
Plugin/ Condition/ UserRole.php, line 59
Class
- UserRole
- Provides a user role condition where all roles are matched.
Namespace
Drupal\rng\Plugin\ConditionCode
public function alterQuery(&$query) {
if ($query
->getEntityTypeId() != 'user') {
throw new \Exception('Query only operates on user entity type.');
}
// Ensure roles in configuration are still existing or valid roles.
$roles = array_intersect_key($this
->getRoles(), $this->configuration['roles']);
if (count($roles)) {
foreach (array_keys($roles) as $role) {
$group = $query
->andConditionGroup();
$group
->condition('roles', $role, '=');
$query
->condition($group);
}
}
}