trait EntityTypeEventSubscriberTrait
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/EntityTypeEventSubscriberTrait.php \Drupal\Core\Entity\EntityTypeEventSubscriberTrait
- 10 core/lib/Drupal/Core/Entity/EntityTypeEventSubscriberTrait.php \Drupal\Core\Entity\EntityTypeEventSubscriberTrait
- 11.x core/lib/Drupal/Core/Entity/EntityTypeEventSubscriberTrait.php \Drupal\Core\Entity\EntityTypeEventSubscriberTrait
Helper methods for EntityTypeListenerInterface.
This allows a class implementing EntityTypeListenerInterface to subscribe and react to entity type events.
Hierarchy
- trait \Drupal\Core\Entity\EntityTypeEventSubscriberTrait
See also
\Symfony\Component\EventDispatcher\EventSubscriberInterface
\Drupal\Core\Entity\EntityTypeListenerInterface
4 files declare their use of EntityTypeEventSubscriberTrait
- EntitySchemaSubscriber.php in core/
modules/ workspaces/ src/ EventSubscriber/ EntitySchemaSubscriber.php - EntitySchemaSubscriber.php in core/
modules/ system/ tests/ modules/ entity_test_update/ src/ EventSubscriber/ EntitySchemaSubscriber.php - EntityTestDefinitionSubscriber.php in core/
modules/ system/ tests/ modules/ entity_test/ src/ EntityTestDefinitionSubscriber.php - ViewsEntitySchemaSubscriber.php in core/
modules/ views/ src/ EventSubscriber/ ViewsEntitySchemaSubscriber.php
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityTypeEventSubscriberTrait.php, line 14
Namespace
Drupal\Core\EntityView source
trait EntityTypeEventSubscriberTrait {
/**
* Gets the subscribed events.
*
* @return array
* An array of subscribed event names.
*
* @see \Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents()
*/
public static function getEntityTypeEvents() {
$event = [
'onEntityTypeEvent',
100,
];
$events[EntityTypeEvents::CREATE][] = $event;
$events[EntityTypeEvents::UPDATE][] = $event;
$events[EntityTypeEvents::DELETE][] = $event;
return $events;
}
/**
* Listener method for any entity type definition event.
*
* @param \Drupal\Core\Entity\EntityTypeEvent $event
* The field storage definition event object.
* @param string $event_name
* The event name.
*/
public function onEntityTypeEvent(EntityTypeEvent $event, $event_name) {
switch ($event_name) {
case EntityTypeEvents::CREATE:
$this->onEntityTypeCreate($event->getEntityType());
break;
case EntityTypeEvents::UPDATE:
$this->onEntityTypeUpdate($event->getEntityType(), $event->getOriginal());
break;
case EntityTypeEvents::DELETE:
$this->onEntityTypeDelete($event->getEntityType());
break;
}
}
/**
* {@inheritdoc}
*/
public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
}
/**
* {@inheritdoc}
*/
public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) {
}
/**
* {@inheritdoc}
*/
public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
}
/**
* {@inheritdoc}
*/
public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array &$sandbox = NULL) {
}
/**
* {@inheritdoc}
*/
public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
EntityTypeEventSubscriberTrait::getEntityTypeEvents | public static | function | Gets the subscribed events. | |
EntityTypeEventSubscriberTrait::onEntityTypeCreate | public | function | 3 | |
EntityTypeEventSubscriberTrait::onEntityTypeDelete | public | function | 3 | |
EntityTypeEventSubscriberTrait::onEntityTypeEvent | public | function | Listener method for any entity type definition event. | |
EntityTypeEventSubscriberTrait::onEntityTypeUpdate | public | function | 4 | |
EntityTypeEventSubscriberTrait::onFieldableEntityTypeCreate | public | function | 2 | |
EntityTypeEventSubscriberTrait::onFieldableEntityTypeUpdate | public | function | 2 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.