menu_node_edit_overview_form_submit

Versions
menu_node_edit
menu_node_edit_overview_form_submit($form, &$form_state)

Custom submit handler for menu overview form.

Code

./menu_node_edit.module, line 418

<?php
function menu_node_edit_overview_form_submit($form, &$form_state) {
  $sections = menu_node_edit_get_sections();
  $remove = array();
  $add = array();
  // Check the menu elements of the form for changes.
  foreach ($form_state['values'] as $key => $value) {
    if (is_array($value) && isset($value['mlid'])) {
      if ($value['menu_node_edit']) {
        $add[$value['mlid']] = $value['mlid'];
      }
      // If access was removed, set the delete array for users.
      else if (!$value['menu_node_edit'] && in_array($value['mlid'], $sections)) {
        $remove[] = $value['mlid'];
      }
    }
  }
  // Run the inserts?
  $diff = array_diff($add, $sections);
  if (!empty($diff)) {
    // Insert the new records.
    foreach ($diff as $mlid) {
      db_query("INSERT INTO {menu_node_edit} (mlid) VALUES (%d)", $mlid);
    }
    drupal_set_message(t('Site sections added.'));
  }
  // Now delete the old ones, if neccessary.
  if (!empty($remove)) {
    foreach ($remove as $mlid) {
      db_query("DELETE FROM {menu_node_edit} WHERE mlid = %d", $mlid);
      db_query("DELETE FROM {menu_node_edit_user} WHERE mlid = %d", $mlid);
    }
    drupal_set_message(t('Site sections removed.'));
  }
  cache_clear_all('menu-access-options', 'cache');
}
?>

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List