You are here

function we_megamenu_entity_delete in Drupal Mega Menu 8.x

Same name and namespace in other branches
  1. 8 we_megamenu.module \we_megamenu_entity_delete()

Implements hook_entity_delete().

File

./we_megamenu.module, line 716
Drupal 8 Mega Menu Module.

Code

function we_megamenu_entity_delete(EntityInterface $entity) {
  if (method_exists($entity, 'getTypedData') && method_exists($entity, 'getEntityTypeId')) {
    $data = $entity
      ->getTypedData();
    $data = $data
      ->toArray();
    $entity_type = $entity
      ->getEntityTypeId();
    switch ($entity_type) {
      case 'menu':
        break;
      case 'menu_link_content':
        $menu_name = $data['menu_name'][0]['value'];
        $config = \Drupal::config('system.theme');
        $theme_name = $config
          ->get('default');
        $menu_uuid = $entity
          ->get('uuid')
          ->getString();
        $menu_uuid = $menu_uuid == 'standard.front_page' ? base_path() : $menu_uuid;
        $menu_config = WeMegaMenuBuilder::loadConfig($menu_name, $theme_name);
        WeMegaMenuBuilder::menuItemDelete($menu_config, $menu_uuid);
        WeMegaMenuBuilder::saveConfig($menu_name, $theme_name, json_encode($menu_config));
        break;
    }
  }
}