You are here

GroupSiblings.php in RNG - Events and Registrations 8.2

File

src/Plugin/EntityReferenceSelection/GroupSiblings.php
View source
<?php

namespace Drupal\rng\Plugin\EntityReferenceSelection;

use Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\rng\Entity\GroupInterface;

/**
 * Provides selection to sibling groups on an event.
 *
 * Should be attached to a `registration_group` entity.
 *
 * @EntityReferenceSelection(
 *   id = "rng:registration_group:siblings",
 *   label = @Translation("Registration group siblings"),
 *   entity_types = {"registration_group"},
 *   group = "siblings",
 *   weight = 1
 * )
 */
class GroupSiblings extends SelectionBase {

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Classes

Namesort descending Description
GroupSiblings Provides selection to sibling groups on an event.