You are here

public static function WeMegaMenuBuilder::menuItemDelete in Drupal Mega Menu 8

Same name and namespace in other branches
  1. 8.x src/WeMegaMenuBuilder.php \Drupal\we_megamenu\WeMegaMenuBuilder::menuItemDelete()

Delete menu item.

Parameters

object $menu_config: Public static function menuItemInsert menu_config.

string $menu_uuid: Public static function menuItemInsert menu_uuid.

1 call to WeMegaMenuBuilder::menuItemDelete()
we_megamenu_entity_delete in ./we_megamenu.module
Implements hook_entity_delete().

File

src/WeMegaMenuBuilder.php, line 410

Class

WeMegaMenuBuilder

Namespace

Drupal\we_megamenu

Code

public static function menuItemDelete($menu_config, $menu_uuid) {
  if (isset($menu_config->menu_config)) {
    $menus = $menu_config->menu_config;
    if (isset($menus) && is_array($menus)) {
      foreach ($menus as $key_menu => $menu) {

        # Remove as root
        if ($key_menu == $menu_uuid) {
          if (isset($menu_config->menu_config[$menu_uuid])) {
            unset($menu_config->menu_config[$menu_uuid]);
          }
        }

        # Remove as leaf
        if (isset($menu->rows_content)) {
          $rows_content = $menu->rows_content;
          foreach ($rows_content as $key_rows => $rows) {
            if (is_array($rows)) {
              foreach ($rows as $key_row_col => $row) {
                if (isset($row->col_content)) {
                  $cols = $row->col_content;
                  if (is_array($cols)) {
                    foreach ($cols as $key_col => $col) {
                      if (isset($col->mlid) && $col->mlid == $menu_uuid) {
                        unset($menu_config->menu_config->{$key_menu}->rows_content[$key_rows][$key_row_col]->col_content[$key_col]);
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}