You are here

public function EventManager::getMeta in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/EventManager.php \Drupal\rng\EventManager::getMeta()
  2. 3.x src/EventManager.php \Drupal\rng\EventManager::getMeta()

Get the meta instance for an event.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: An event entity.

Return value

\Drupal\rng\EventMetaInterface|null An event meta object.

Throws

\Drupal\rng\Exception\InvalidEventException If the $entity is not an event.

Overrides EventManagerInterface::getMeta

File

src/EventManager.php, line 46

Class

EventManager
Event manager for RNG.

Namespace

Drupal\rng

Code

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];
}