If you go to a menu settings page via the tool-icon next to it a redirection parameter is added to redirect you back to the page you came from after you have altered something in the settings. However, when trying to delete the menu you will be redirected back without successfully deleting the menu.

Comments

neRok’s picture

Version: 7.15 » 7.x-dev
Priority: Minor » Normal
Status: Active » Needs work

Confirmed using 7.22. Steps to reproduce;

  1. Create a menu
  2. Move the menus block to a sidebar or similar
  3. Visit a page showing the block, open the contextual links (gear icon), and choose 'edit menu'.
    At this time, the url is admin/structure/menu/manage/menu-MYMENU/edit?destination=PAGEURL
  4. Press delete. You are redirected back to page (PAGEURL), and menu is not deleted.

If you visit admin/structure/menu/manage/menu-MYMENU/edit and press delete, you are taken to a delete menu confirmation form at admin/structure/menu/manage/menu-MYMENU/delete. The two redirects must be conflicting.

neRok’s picture

Did a bit of investigating. This page describes the problem https://api.drupal.org/api/drupal/includes!form.inc/function/drupal_redirect_form/7

If none of the above conditions has prevented redirection, then the redirect is accomplished by calling drupal_goto(), passing in the value of $form_state['redirect'] if it is set, or the current path if it is not. drupal_goto() preferentially uses the value of $_GET['destination'] (the 'destination' URL query string) if it is present, so this will override any values set by $form_state['redirect'].

With this is mind, I believe replacing menu_custom_delete_submit(), which is in menu.admin.inc, with the following code will solve the problem and maintain the original redirect.

function menu_custom_delete_submit($form, &$form_state) {

  if (isset($_GET['destination'])) {
    $form_state['redirect'] = array(
      'admin/structure/menu/manage/' . $form_state['values']['menu_name'] . '/delete',
      array(
        'query' => array(
          'destination' => $_GET['destination'],
        ),
      ),
    );
    unset($_GET['destination']);
  }
  else {
    $form_state['redirect'] = 'admin/structure/menu/manage/' . $form_state['values']['menu_name'] . '/delete';
  }

}

I am unable to create a patch at the moment...

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.