You are here

function weather_weather_display_delete in Weather 2.0.x

Same name and namespace in other branches
  1. 8 weather.module \weather_weather_display_delete()

Removes related entities on Weather Display delete.

Implements hook_ENTITY_TYPE_delete().

File

./weather.module, line 89
Main module file with hooks implementations.

Code

function weather_weather_display_delete(WeatherDisplayInterface $entity) {

  // Remove related Display Places.
  $displayPlaces = Drupal::entityTypeManager()
    ->getStorage('weather_display_place')
    ->loadByProperties([
    'display_type' => $entity->type->value,
    'display_number' => $entity->number->value,
  ]);
  foreach ($displayPlaces as $displayPlace) {
    $displayPlace
      ->delete();
  }

  // Remove related block instances.
  $blocks = Drupal::entityTypeManager()
    ->getStorage('block')
    ->loadByProperties([
    'plugin' => 'weather_system_display_block:' . $entity
      ->id(),
  ]);
  foreach ($blocks as $block) {
    $block
      ->delete();
  }
}