/** * Recursively deletes menu_items * * @param string $menu_name name of the menu item to delete * @param array $menu_items array of menu items * * @return void */ function menu_builder_delete_menu_item($menu_name, &$menu_items) { if (empty($menu_name) || empty($menu_items)) { return; } unset($menu_items[$menu_name]); foreach ($menu_items as $key => $item) { if ($item['parent_name'] == $menu_name) { menu_builder_delete_menu_item($key, $menu_items); } } }
<?php $name = get_input('item_name'); $menu_name = get_input('menu_name'); $menu = new \ColdTrick\MenuBuilder\Menu($menu_name); $menu_items = $menu->getMenuConfig(); if (empty($menu_items)) { return; } menu_builder_delete_menu_item($name, $menu_items); $menu->setMenuConfig($menu_items); system_message(elgg_echo('menu_builder:actions:delete:success')); forward("admin/appearance/menu_items?menu_name={$menu_name}");