class EventManager in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/EventManager.php \Drupal\rng\EventManager
- 3.x src/EventManager.php \Drupal\rng\EventManager
Event manager for RNG.
Hierarchy
- class \Drupal\rng\EventManager implements EventManagerInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
Expanded class hierarchy of EventManager
1 string reference to 'EventManager'
1 service uses EventManager
File
- src/
EventManager.php, line 14
Namespace
Drupal\rngView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EventManager:: |
protected | property | Event type storage. | |
EventManager:: |
protected | property | An array of event meta instances. | |
EventManager:: |
function |
Get event type config for an event bundle. Overrides EventManagerInterface:: |
||
EventManager:: |
function |
Gets all event types associated with an entity type. Overrides EventManagerInterface:: |
||
EventManager:: |
function |
Get all event types configuration entities. Overrides EventManagerInterface:: |
||
EventManager:: |
public | function |
Get the meta instance for an event. Overrides EventManagerInterface:: |
|
EventManager:: |
function |
Invalidate cache for an event type. Overrides EventManagerInterface:: |
||
EventManager:: |
function |
Invalidate cache for events types. Overrides EventManagerInterface:: |
||
EventManager:: |
public | function |
Determines if an entity is an event. Overrides EventManagerInterface:: |
|
EventManager:: |
function | Constructs a new EventManager object. | ||
EventManagerInterface:: |
constant | ID of an `boolean` field attached to an event bundle. | ||
EventManagerInterface:: |
constant | ID of an `integer` field attached to an event bundle. | ||
EventManagerInterface:: |
constant | ID of an `email` field attached to an event bundle. | ||
EventManagerInterface:: |
constant | ID of an `entity_reference` field attached to an event bundle. | ||
EventManagerInterface:: |
constant | ID of an `integer` field attached to an event bundle. | ||
EventManagerInterface:: |
constant | ID of an `integer` field attached to an event bundle. | ||
EventManagerInterface:: |
constant | ID of an `entity_reference` field attached to an event bundle. | ||
EventManagerInterface:: |
constant | ID of an `boolean` field attached to an event bundle. |