You are here

function admin_menu_overview_form_submit in Admin 6

Submit handler for the admin menu overview form.

1 string reference to 'admin_menu_overview_form_submit'
admin_form_menu_overview_form_alter in ./admin.admin.inc
Implementation of hook_form_alter() for menu_overview_form.

File

./admin.admin.inc, line 110

Code

function admin_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 children.
  // 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'];
        }
      }

      // 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'];
      }

      // Admin is also a special case -- we need to set its flag in the options array.
      if ($element['admin']['#value'] != $element['admin']['#default_value']) {
        $element['#item']['options']['admin'] = $element['admin']['#value'];
        $updated_items[$mlid] = $element['#item'];
      }
    }
  }

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