[development] Hook_menu_alter doesn't work if menu item changed

Nancy Wichmann nan_wich at bellsouth.net
Mon Apr 27 20:07:21 UTC 2009

I am not the menu expert here, so I am sure that there is something wrong
with my little change:
function menu_overview_form_submit($form, &$form_state) {
  // When dealing with saving menu items, the order in which these items are
  // saved is critical. If a changed child item is saved before its parent,
  // the child item could be saved with an invalid path past its immediate
  // parent. To prevent this, save items in the form in the same order they
  // are sent by $_POST, ensuring parents are saved first, then their
  // See http://drupal.org/node/181126#comment-632270
  $order = array_flip(array_keys($form['#post'])); // Get the $_POST order.
  $form = array_merge($order, $form); // Update our original form with the
new order.

  $updated_items = array();
  $fields = array('expanded', 'weight', 'plid');
  foreach (element_children($form) as $mlid) {
    if (isset($form[$mlid]['#item'])) {
      $element = $form[$mlid];
      // Update any fields that have changed in this menu item.
      foreach ($fields as $field) {
        if ($element[$field]['#value'] !=
$element[$field]['#default_value']) {
          $element['#item'][$field] = $element[$field]['#value'];
          $updated_items[$mlid] = $element['#item'];
          $updated_items[$mlid]['customized'] = $field == 'plid';       //
<-- only “plid” is really customized.
      // Hidden is a special case, the value needs to be reversed.
      if ($element['hidden']['#value'] !=
$element['hidden']['#default_value']) {
        $element['#item']['hidden'] = !$element['hidden']['#value'];
        $updated_items[$mlid] = $element['#item'];

  // Save all our changed items to the database.
  foreach ($updated_items as $item) {
//    $item['customized'] = 1;

Frankly, I don’t think “expanded” is really customized either.

I tested this on my dev site and got the results I want.  So now Karoly or
Earl will tell this ditzy blonde why this is not the solution.

Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. - Martin L. King, Jr.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.drupal.org/pipermail/development/attachments/20090427/b353f860/attachment-0001.htm>
-------------- next part --------------

No virus found in this outgoing message.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.12.4/2082 - Release Date: 4/27/2009 6:19 AM

More information about the development mailing list