You are here

class RngRegistrationCreationSubscriber in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/EventSubscriber/RngRegistrationCreationSubscriber.php \Drupal\rng\EventSubscriber\RngRegistrationCreationSubscriber

Class RngRegistrationCreationSubscriber.

Hierarchy

Expanded class hierarchy of RngRegistrationCreationSubscriber

1 string reference to 'RngRegistrationCreationSubscriber'
rng.services.yml in ./rng.services.yml
rng.services.yml
1 service uses RngRegistrationCreationSubscriber
rng.registration_creation_subscriber in ./rng.services.yml
Drupal\rng\EventSubscriber\RngRegistrationCreationSubscriber

File

src/EventSubscriber/RngRegistrationCreationSubscriber.php, line 13

Namespace

Drupal\rng\EventSubscriber
View source
class RngRegistrationCreationSubscriber implements EventSubscriberInterface {

  /**
   * Drupal\rng\EventManagerInterface definition.
   *
   * @var \Drupal\rng\EventManagerInterface
   */
  protected $rngEventManager;

  /**
   * RngRegistrationCreationSubscriber constructor.
   *
   * @param \Drupal\rng\EventManagerInterface $rng_event_manager
   *   The rng event manager.
   */
  public function __construct(EventManagerInterface $rng_event_manager) {
    $this->rngEventManager = $rng_event_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events['rng.registration_create'][] = [
      'invalidEntityBundle',
    ];
    $events['rng.registration_create'][] = [
      'missingRegistrationType',
    ];
    $events['rng.registration_create'][] = [
      'acceptingRegistration',
    ];
    $events['rng.registration_create'][] = [
      'canRegisterProxies',
    ];

    // Setting this to a lower weight so it can potentially be easily skipped.
    $events['rng.registration_create'][] = [
      'remainingCapacity',
      -1,
    ];
    return $events;
  }

  /**
   * Determines if there is an invalid entity bundle.
   *
   * @param \Drupal\rng\Event\RegistrationAccessEvent $event
   */
  public function invalidEntityBundle(RegistrationAccessEvent $event) {
    $meta = $this
      ->getMeta($event
      ->getContext());

    // $entity_bundle is omitted for registration type list at
    // $event_path/register
    if ($event
      ->getEntityBundle() && ($registration_type = RegistrationType::load($event
      ->getEntityBundle()))) {
      if (!$meta
        ->registrationTypeIsValid($registration_type)) {
        $event
          ->setAccess(FALSE);
      }
    }
  }

  /**
   * Determines if there are no registration types configured.
   *
   * @param \Drupal\rng\Event\RegistrationAccessEvent $event
   */
  public function missingRegistrationType(RegistrationAccessEvent $event) {
    $meta = $this
      ->getMeta($event
      ->getContext());
    if (!$meta
      ->getRegistrationTypeIds()) {
      $event
        ->setAccess(FALSE);
    }
  }

  /**
   * Determines if there is any remaining capacity.
   *
   * @param \Drupal\rng\Event\RegistrationAccessEvent $event
   */
  public function acceptingRegistration(RegistrationAccessEvent $event) {
    $meta = $this
      ->getMeta($event
      ->getContext());
    if (!$meta
      ->isAcceptingRegistrations()) {
      $event
        ->setAccess(FALSE);
    }
  }

  /**
   * Determines if there is any remaining capacity.
   *
   * @param \Drupal\rng\Event\RegistrationAccessEvent $event
   */
  public function remainingCapacity(RegistrationAccessEvent $event) {
    $meta = $this
      ->getMeta($event
      ->getContext());
    if (!$meta
      ->allowWaitList() && $meta
      ->remainingRegistrantCapacity() < 1) {
      $event
        ->setAccess(FALSE);
    }
  }

  /**
   * Determines if user can register proxies.
   *
   * @param \Drupal\rng\Event\RegistrationAccessEvent $event
   */
  public function canRegisterProxies(RegistrationAccessEvent $event) {
    $meta = $this
      ->getMeta($event
      ->getContext());
    if (!$meta
      ->canRegisterProxyIdentities()) {
      $event
        ->setAccess(FALSE);
    }
  }

  /**
   * Get the event meta.
   *
   * @param array $context
   *
   * @return \Drupal\rng\EventMetaInterface|null
   *   The event meta or NULL.
   *
   * @throws \Drupal\rng\Exception\InvalidEventException
   */
  protected function getMeta(array $context) {
    return $this->rngEventManager
      ->getMeta($context['event']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RngRegistrationCreationSubscriber::$rngEventManager protected property Drupal\rng\EventManagerInterface definition.
RngRegistrationCreationSubscriber::acceptingRegistration public function Determines if there is any remaining capacity.
RngRegistrationCreationSubscriber::canRegisterProxies public function Determines if user can register proxies.
RngRegistrationCreationSubscriber::getMeta protected function Get the event meta.
RngRegistrationCreationSubscriber::getSubscribedEvents public static function
RngRegistrationCreationSubscriber::invalidEntityBundle public function Determines if there is an invalid entity bundle.
RngRegistrationCreationSubscriber::missingRegistrationType public function Determines if there are no registration types configured.
RngRegistrationCreationSubscriber::remainingCapacity public function Determines if there is any remaining capacity.
RngRegistrationCreationSubscriber::__construct public function RngRegistrationCreationSubscriber constructor.