You are here

function nodehierarchy_menu_overview_form in Node Hierarchy 6.2

Same name and namespace in other branches
  1. 6.3 nodehierarchy.module \nodehierarchy_menu_overview_form()
  2. 7.4 nodehierarchy_menu/nodehierarchy_menu.module \nodehierarchy_menu_overview_form()
  3. 7.2 nodehierarchy.module \nodehierarchy_menu_overview_form()

Form for editing an entire menu tree at once.

Shows for one menu the menu items accessible to the current user and relevant operations. This is a clone of the menu.module function menu_overview_form but with nodehierarchy items not loaded if they don not have a menu presence.

1 string reference to 'nodehierarchy_menu_overview_form'
nodehierarchy_menu_alter in ./nodehierarchy.module
Implementation of hook_menu_alter().

File

./nodehierarchy.module, line 303
A module to make nodes hierarchical.

Code

function nodehierarchy_menu_overview_form(&$form_state, $menu) {
  if (!module_exists('menu')) {
    return array();
  }

  // This should have been loaded by the menu load system, but may not have been if menu_access.module is installed.
  module_load_include('inc', 'menu', 'menu.admin');

  // Count how many elements are omitted.
  $count_sql = "SELECT COUNT(*) FROM {menu_links} ml WHERE ml.menu_name = '%s' AND ml.module = 'nodehierarchy' AND ml.hidden != 0";
  $hidden = db_result(db_query($count_sql, $menu['menu_name']));

  // Use the default menu behaviour unless specified.
  if ($hidden < variable_get('nodehierarchy_hide_disabled_threshold', 100) || isset($_GET['all']) || variable_get('nodehierarchy_menu_module_edit', FALSE)) {
    $form = menu_overview_form($form_state, $menu);
  }
  else {
    global $menu_admin;

    // Fetch all the menu items which are not node hierarchy non-displaying items.
    $sql = "\n      SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*\n      FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path\n      WHERE ml.menu_name = '%s'\n        AND (ml.module != 'nodehierarchy' OR ml.hidden = 0)\n      ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";
    $result = db_query($sql, $menu['menu_name']);
    $tree = menu_tree_data($result);
    $node_links = array();
    menu_tree_collect_node_links($tree, $node_links);

    // We indicate that a menu administrator is running the menu access check.
    $menu_admin = TRUE;
    menu_tree_check_access($tree, $node_links);
    $menu_admin = FALSE;
    $form = _menu_overview_tree_form($tree);
    $form['#menu'] = $menu;
    if (element_children($form)) {
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save configuration'),
      );
    }
    else {
      $form['empty_menu'] = array(
        '#value' => t('There are no menu items yet.'),
      );
    }
    $form['hidden']['#value'] = $hidden;
    $form['hidden']['#type'] = 'value';
  }

  // Set the form handlers so the behaviour is the same as the regular menu form.
  $form['#submit'][] = 'menu_overview_form_submit';
  $form['#validate'][] = 'menu_overview_form_validate';
  return $form;
}