You are here

function og_menu_entity_delete in Organic Groups Menu (OG Menu) 8

Implements hook_entity_delete().

File

./og_menu.module, line 63
Main functions and hook implementations of the og_menu module.

Code

function og_menu_entity_delete(EntityInterface $entity) {

  // If a group is deleted, delete its associated OG Menus.
  if (Og::isGroup($entity
    ->getEntityTypeId(), $entity
    ->bundle())) {

    // This is only needed if Organic Groups is not taking care of orphaned
    // group content itself.
    if (!\Drupal::config('og.settings')
      ->get('delete_orphans')) {
      $storage = \Drupal::entityTypeManager()
        ->getStorage('ogmenu_instance');
      $properties = [
        OgGroupAudienceHelper::DEFAULT_FIELD => $entity
          ->id(),
      ];

      /** @var \Drupal\og_menu\Entity\OgMenuInstance $instance */
      foreach ($storage
        ->loadByProperties($properties) as $instance) {
        $instance
          ->delete();
      }
    }
  }
}