public static function Group::preDelete in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Entity/Group.php \Drupal\rng\Entity\Group::preDelete()
- 3.x src/Entity/Group.php \Drupal\rng\Entity\Group::preDelete()
Parameters
static[] $entities: An array of registration_group entities.
Overrides EntityBase::preDelete
File
- src/
Entity/ Group.php, line 214
Class
- Group
- Defines the application group entity class.
Namespace
Drupal\rng\EntityCode
public static function preDelete(EntityStorageInterface $storage, array $entities) {
/** @var \Drupal\rng\EventManagerInterface $event_manager */
$event_manager = \Drupal::service('rng.event_manager');
foreach ($entities as $group) {
if ($event = $group
->getEvent()) {
// Dont bother if the entity is no longer an event, or event is deleted.
try {
$event_meta = $event_manager
->getMeta($event);
// Remove entity field references from the event to group in
// $event->{EventManagerInterface::FIELD_REGISTRATION_GROUPS}
$event_meta
->removeGroup($group
->id())
->save();
// Remove entity field references from registrations to group.
foreach ($event_meta
->getRegistrations() as $registration) {
$registration
->removeGroup($group
->id())
->save();
}
} catch (InvalidEventException $e) {
}
}
}
}