You are here

function bat_unit_entity_delete in Booking and Availability Management Tools for Drupal 8

Same name and namespace in other branches
  1. 7 modules/bat_unit/bat_unit.module \bat_unit_entity_delete()

Implements hook_entity_delete().

File

modules/bat_unit/bat_unit.module, line 130
Manage units - Units are things that can be booked for some period of time. (e.g. rooms - but also villas bungalows, cars, drills, you-get-the-idea etc.)

Code

function bat_unit_entity_delete(EntityInterface $entity) {
  if ($entity
    ->getEntityTypeId() == 'bat_unit_type') {

    // When delete a Type remove all related Units.
    $units = bat_unit_load_multiple(FALSE, [
      'unit_type_id' => $entity
        ->id(),
    ]);
    foreach ($units as $unit) {
      $unit
        ->delete();
    }
  }
}