public function Event::delete in Booking and Availability Management Tools for Drupal 8
Deletes an entity permanently.
Throws
\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.
Overrides EntityBase::delete
File
- modules/
bat_event/ src/ Entity/ Event.php, line 280 - Contains \Drupal\bat_event\Entity\Event.
Class
- Event
- Defines the Event entity.
Namespace
Drupal\bat_event\EntityCode
public function delete() {
$langcode = $this->defaultLangcode;
$event_type = bat_event_type_load($this
->bundle());
// Construct target entity reference field name using this event type's target entity type.
$target_field_name = 'event_' . $event_type
->getTargetEntityType() . '_reference';
// Check if the event had a unit associated with it and if so update the
// availability calendar.
if ($this
->getTranslation($langcode)
->get($target_field_name) !== FALSE) {
$event_target_entity_reference = $this
->getTranslation($langcode)
->get($target_field_name);
$target_entity_id = $event_target_entity_reference
->referencedEntities()[0]
->id();
// Load the referenced entity.
if ($target_entity = \Drupal::entityTypeManager()
->getStorage($event_type
->getTargetEntityType())
->load($target_entity_id)) {
$unit = new Unit($target_entity_id, $target_entity
->getEventDefaultValue($event_type
->id()));
$this
->batStoreSave($unit, $this
->getStartDate(), $this
->getEndDate()
->sub(new \DateInterval('PT1M')), $event_type
->id(), $event_type
->getEventGranularity(), $unit
->getDefaultValue(), $this
->get('id')->value, TRUE);
}
}
parent::delete();
}