You are here

protected function GroupSiblings::buildEntityQuery in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/EntityReferenceSelection/GroupSiblings.php \Drupal\rng\Plugin\EntityReferenceSelection\GroupSiblings::buildEntityQuery()
  2. 3.x src/Plugin/EntityReferenceSelection/GroupSiblings.php \Drupal\rng\Plugin\EntityReferenceSelection\GroupSiblings::buildEntityQuery()

Builds an EntityQuery to get referenceable entities.

Parameters

string|null $match: (Optional) Text to match the label against. Defaults to NULL.

string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".

Return value

\Drupal\Core\Entity\Query\QueryInterface The EntityQuery object with the basic conditions and sorting applied to it.

Overrides DefaultSelection::buildEntityQuery

File

src/Plugin/EntityReferenceSelection/GroupSiblings.php, line 27

Class

GroupSiblings
Provides selection to sibling groups on an event.

Namespace

Drupal\rng\Plugin\EntityReferenceSelection

Code

protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
  $query = parent::buildEntityQuery($match, $match_operator);
  if (($registration_group = $this->configuration['entity']) instanceof GroupInterface) {

    /** @var \Drupal\rng\Entity\GroupInterface $registration_group */
    if (($event = $registration_group
      ->getEvent()) instanceof EntityInterface) {
      $group = $query
        ->andConditionGroup()
        ->condition('event__target_type', $event
        ->getEntityTypeId(), '=')
        ->condition('event__target_id', $event
        ->id(), '=');
      $query
        ->condition($group);
    }
    $id_key = $registration_group
      ->getEntityType()
      ->getKey('id');
    $query
      ->condition($id_key, [
      $registration_group
        ->id(),
    ], 'NOT IN');
  }
  $query
    ->condition('source', NULL, 'IS NULL');
  return $query;
}