function menu_overview_form

Form constructor to edit an entire menu tree at once.

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

This form constructor can be integrated as a section into another form. It relies on the following keys in $form_state:

  • menu: A loaded menu definition, as returned by menu_load().
  • menu_overview_form_parents: An array containing the parent keys to this form.

Forms integrating this section should call menu_overview_form_submit() from their form submit handler.

1 call to menu_overview_form()
MenuFormController::form in drupal/core/modules/menu/lib/Drupal/menu/MenuFormController.php
Overrides Drupal\Core\Entity\EntityFormController::form().

File

drupal/core/modules/menu/menu.admin.inc, line 65
Administrative page callbacks for menu module.

Code

function menu_overview_form($form, &$form_state) {
  global $menu_admin;

  // Ensure that menu_overview_form_submit() knows the parents of this form
  // section.
  $form['#tree'] = TRUE;
  $form['#theme'] = 'menu_overview_form';
  $form_state += array(
    'menu_overview_form_parents' => array(),
  );
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'menu') . '/css/menu.admin.css',
  );
  $links = array();
  $query = Drupal::entityQuery('menu_link')
    ->condition('menu_name', $form_state['menu']
    ->id());
  for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
    $query
      ->sort('p' . $i, 'ASC');
  }
  $result = $query
    ->execute();
  if (!empty($result)) {
    $links = menu_link_load_multiple($result);
  }
  $delta = max(count($links), 50);
  $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;

  // Inline the "Add link" action so it displays right above the table of
  // links. No access check needed, since this form has the same access
  // restriction as adding menu items to the menu.
  $form['inline_actions'] = array(
    '#prefix' => '<ul class="action-links">',
    '#suffix' => '</ul>',
  );
  $form['inline_actions']['add'] = array(
    '#theme' => 'menu_local_action',
    '#link' => array(
      'href' => 'admin/structure/menu/manage/' . $form_state['menu']
        ->id() . '/add',
      'title' => t('Add link'),
    ),
  );
  $form = array_merge($form, _menu_overview_tree_form($tree, $delta));
  $form['#empty_text'] = t('There are no menu links yet. <a href="@link">Add link</a>.', array(
    '@link' => url('admin/structure/menu/manage/' . $form_state['menu']
      ->id() . '/add'),
  ));
  return $form;
}