You are here

class EventManager in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/EventManager.php \Drupal\rng\EventManager
  2. 3.x src/EventManager.php \Drupal\rng\EventManager

Event manager for RNG.

Hierarchy

Expanded class hierarchy of EventManager

1 string reference to 'EventManager'
rng.services.yml in ./rng.services.yml
rng.services.yml
1 service uses EventManager
rng.event_manager in ./rng.services.yml
Drupal\rng\EventManager

File

src/EventManager.php, line 14

Namespace

Drupal\rng
View source
class EventManager implements EventManagerInterface {
  use ContainerAwareTrait;

  /**
   * An array of event meta instances.
   *
   * @var \Drupal\rng\EventMeta[]
   */
  protected $event_meta = [];

  /**
   * Event type storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $eventTypeStorage;

  /**
   * Constructs a new EventManager object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  function __construct(EntityManagerInterface $entity_manager) {
    $this->eventTypeStorage = $entity_manager
      ->getStorage('event_type');
  }

  /**
   * {@inheritdoc}
   */
  public function getMeta(EntityInterface $entity) {
    $entity_type = $entity
      ->getEntityTypeId();
    $id = $entity
      ->id();
    if (!$this
      ->isEvent($entity)) {
      throw new InvalidEventException(sprintf('%s: %s is not an event bundle.', $entity
        ->getEntityTypeId(), $entity
        ->bundle()));
    }
    if (!isset($this->event_meta[$entity_type][$id])) {
      $this->event_meta[$entity_type][$id] = EventMeta::createInstance($this->container, $entity);
    }
    return $this->event_meta[$entity_type][$id];
  }

  /**
   * {@inheritdoc}
   */
  public function isEvent(EntityInterface $entity) {
    return (bool) $this
      ->eventType($entity
      ->getEntityTypeId(), $entity
      ->bundle());
  }

  /**
   * {@inheritdoc}
   */
  function eventType($entity_type, $bundle) {
    $ids = $this->eventTypeStorage
      ->getQuery()
      ->condition('entity_type', $entity_type, '=')
      ->condition('bundle', $bundle, '=')
      ->execute();
    if ($ids) {
      return $this->eventTypeStorage
        ->load(reset($ids));
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  function eventTypeWithEntityType($entity_type) {
    $ids = $this->eventTypeStorage
      ->getQuery()
      ->condition('entity_type', $entity_type, '=')
      ->execute();
    if ($ids) {
      return $this->eventTypeStorage
        ->loadMultiple($ids);
    }
    return [];
  }

  /**
   * {@inheritdoc}
   */
  function getEventTypes() {

    /** @var \Drupal\rng\EventTypeInterface[] $event_types */
    $entity_type_bundles = [];
    foreach ($this->eventTypeStorage
      ->loadMultiple() as $entity) {
      $entity_type_bundles[$entity
        ->getEventEntityTypeId()][$entity
        ->getEventBundle()] = $entity;
    }
    return $entity_type_bundles;
  }

  /**
   * {@inheritdoc}
   */
  function invalidateEventTypes() {
    $event_types = $this
      ->getEventTypes();
    foreach ($event_types as $i => $bundles) {
      foreach ($bundles as $b => $event_type) {

        /** @var \Drupal\rng\EventTypeInterface $event_type */
        $this
          ->invalidateEventType($event_type);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  function invalidateEventType(EventTypeInterface $event_type) {
    Cache::invalidateTags($event_type
      ->getCacheTags());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventManager::$eventTypeStorage protected property Event type storage.
EventManager::$event_meta protected property An array of event meta instances.
EventManager::eventType function Get event type config for an event bundle. Overrides EventManagerInterface::eventType
EventManager::eventTypeWithEntityType function Gets all event types associated with an entity type. Overrides EventManagerInterface::eventTypeWithEntityType
EventManager::getEventTypes function Get all event types configuration entities. Overrides EventManagerInterface::getEventTypes
EventManager::getMeta public function Get the meta instance for an event. Overrides EventManagerInterface::getMeta
EventManager::invalidateEventType function Invalidate cache for an event type. Overrides EventManagerInterface::invalidateEventType
EventManager::invalidateEventTypes function Invalidate cache for events types. Overrides EventManagerInterface::invalidateEventTypes
EventManager::isEvent public function Determines if an entity is an event. Overrides EventManagerInterface::isEvent
EventManager::__construct function Constructs a new EventManager object.
EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS constant ID of an `boolean` field attached to an event bundle.
EventManagerInterface::FIELD_CAPACITY constant ID of an `integer` field attached to an event bundle.
EventManagerInterface::FIELD_EMAIL_REPLY_TO constant ID of an `email` field attached to an event bundle.
EventManagerInterface::FIELD_REGISTRATION_GROUPS constant ID of an `entity_reference` field attached to an event bundle.
EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MAXIMUM constant ID of an `integer` field attached to an event bundle.
EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MINIMUM constant ID of an `integer` field attached to an event bundle.
EventManagerInterface::FIELD_REGISTRATION_TYPE constant ID of an `entity_reference` field attached to an event bundle.
EventManagerInterface::FIELD_STATUS constant ID of an `boolean` field attached to an event bundle.