Form submission handler.
array $form: An associative array containing the structure of the form.
array $form_state: An associative array containing the current state of the form.
Overrides FormInterface::submitForm
public function submitForm(array &$form, array &$form_state) {
$form_state['redirect'] = 'admin/structure/menu';
// System-defined menus may not be deleted - only menus defined by this module.
$system_menus = menu_list_system_menus();
if (isset($system_menus[$this->menu
->id()])) {
return;
}
// Reset all the menu links defined by the system via hook_menu().
// @todo Convert this to an EFQ once we figure out 'ORDER BY m.number_parts'.
$result = db_query("SELECT mlid FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.menu_name = :menu AND ml.module = 'system' ORDER BY m.number_parts ASC", array(
':menu' => $this->menu
->id(),
), array(
'fetch' => \PDO::FETCH_ASSOC,
))
->fetchCol();
$menu_links = menu_link_load_multiple($result);
foreach ($menu_links as $link) {
$link
->reset();
}
// Delete all links to the overview page for this menu.
$menu_links = entity_load_multiple_by_properties('menu_link', array(
'link_path' => 'admin/structure/menu/manage/' . $this->menu
->id(),
));
menu_link_delete_multiple(array_keys($menu_links));
// Delete the custom menu and all its menu links.
$this->menu
->delete();
$t_args = array(
'%title' => $this->menu
->label(),
);
drupal_set_message(t('The custom menu %title has been deleted.', $t_args));
watchdog('menu', 'Deleted custom menu %title and all its menu links.', $t_args, WATCHDOG_NOTICE);
}