1.20.x menu.admin.inc menu_overview_form($form, &$form_state, $menu)

Form for editing an entire menu tree at once.

Shows for one menu the menu links accessible to the current user and relevant operations.

File

modules/menu/menu.admin.inc, line 70
Admin page callbacks for the Menu module.

Code

function menu_overview_form($form, &$form_state, $menu) {
  global $menu_admin;
  $form['#attached']['css'] = array(backdrop_get_path('module', 'menu') . '/css/menu.css');

  $default_language = language_default();
  $filter_langcode = isset($_GET['langcode']) ? $_GET['langcode'] : $default_language->langcode;

  $form['langcode'] = array(
    '#title' => t('Show menu in language'),
    '#type' => 'select',
    '#options' => language_list(TRUE, TRUE),
    '#empty_value' => LANGUAGE_NONE,
    '#empty_option' => t('All languages'),
    '#default_value' => $filter_langcode,
    '#access' => module_exists('language'),
    '#weight' => -10,
    '#description' => t('Show menu links for a given language. Menu links with the "All" language will be shown in every language.'),
  );
  $form['langcode_filter'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
    '#attributes' => array('class' => array('button-primary')),
    '#submit' => array('menu_overview_form_language_filter_submit'),
  );

  $sql = "
    SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
    FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
    WHERE ml.menu_name = :menu
    ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";
  $result = db_query($sql, array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
  $links = array();
  foreach ($result as $item) {
    $links[] = $item;
  }
  $tree = menu_tree_data($links);
  $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;

  $tree_langcode = $filter_langcode === LANGUAGE_NONE ? NULL : $filter_langcode;
  $form = array_merge($form, _menu_overview_tree_form($tree, $tree_langcode));
  $form['#menu'] = $menu;

  if (count($links)) {
    $form['actions'] = array('#type' => 'actions');
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save configuration'),
    );
  }
  else {
    $form['#empty_text'] = t('There are no menu links yet. <a href="@link">Add link</a>.', array('@link' => url('admin/structure/menu/manage/' . $form['#menu']['menu_name'] . '/add')));
  }
  return $form;
}