When a node is already in a menu, it is possible to choose that menu item as it's own parent. Doing this results in an PHP fatal error: "maximum execution time of 30 seconds exceeded". Probably due an infinite loop somewhere. Anyway, the real problem is not the PHP but the fact that you can choose the node itself or one of it's children as parent.

I created a patch for this problem. The patch applies to the 7.x-3.x-dev version. A small modification is need for the 7.x-3.0-alpha5 version.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

seanB’s picture

Issue summary: View changes

This patch doesn't work (anymore?). The $exclude parameter of _hs_menu_apply_config() expects an array of the menu name and item.

The form_alter function needs to be:

/**
 * Implements hook_form_FORMID_alter().
 *
 * Alter the node form's menu form.
 */
function hs_menu_form_node_form_alter(&$form, &$form_state) {
  if (isset($form['menu']['link']['parent']) && $form['menu']['#access']) {
    unset($form['menu']['link']['parent']['#options']);
    $form['menu']['link']['parent']['#type'] = 'hierarchical_select';
    // Get menu name, needed to exclude current node
    $menu_name = explode(':', $form['menu']['link']['parent']['#default_value']);
    _hs_menu_apply_config($form['menu']['link']['parent'], array($menu_name[0], $form['menu']['link']['mlid']['#value'])); // Exclude current node

    // Set custom submit callback.
    array_unshift($form['#submit'], 'hs_menu_node_form_submit');
  }
}
seanB’s picture

Status: Active » Needs review
FileSize
979 bytes

New patch is attached with some small changed to previous comment.

Demoshane’s picture

Hello,
we have this issue and it's very prone the crash even whole server if user selects the node itself as parent. I improved the patch a little bit HOWEVER it seems that exclude doesn't work for some reason (Also the additional function $params['exclude'] was always empty so added creation of that). As working solution for now this has jQuery based (inline) failsafe to remove node itself from the parent list.

  • stefan.r committed 2b8d6dd on 7.x-3.x authored by Demoshane
    Issue #1997078 by seanB, Demoshane, noneTaken: HS menu: Exclude current...
stefan.r’s picture

Status: Needs review » Fixed

Committed, thanks!

stefan.r’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

stefan.r’s picture