Commit 5c90f1b8 authored by webchick's avatar webchick

Issue #663946 by David_Rothstein, Gábor Hojtsy, sun, mrfelton, jenlampton,...

Issue #663946 by David_Rothstein, Gábor Hojtsy, sun, mrfelton, jenlampton, idflood: Merge 'List links' page into 'Edit menu' page.
parent fb08e2f2
......@@ -271,7 +271,7 @@ private function doAdminTests($user) {
// Add forum to the Tools menu.
$edit = array();
$this->drupalPost('admin/structure/menu/manage/tools', $edit, t('Save configuration'));
$this->drupalPost('admin/structure/menu/manage/tools', $edit, t('Save'));
$this->assertResponse(200);
// Edit forum taxonomy.
......
......@@ -21,6 +21,7 @@ class MenuFormController extends EntityFormController {
public function form(array $form, array &$form_state, EntityInterface $menu) {
$form = parent::form($form, $form_state, $menu);
$system_menus = menu_list_system_menus();
$form_state['menu'] = &$menu;
$form['label'] = array(
'#type' => 'textfield',
......@@ -50,6 +51,19 @@ public function form(array $form, array &$form_state, EntityInterface $menu) {
'#title' => t('Description'),
'#default_value' => $menu->description,
);
// Add menu links administration form for existing menus.
if (!$menu->isNew() || isset($system_menus[$menu->id()])) {
// Form API supports constructing and validating self-contained sections
// within forms, but does not allow to handle the form section's submission
// equally separated yet. Therefore, we use a $form_state key to point to
// the parents of the form section.
// @see menu_overview_form_submit()
$form_state['menu_overview_form_parents'] = array('links');
$form['links'] = array();
$form['links'] = menu_overview_form($form['links'], $form_state);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
......@@ -71,6 +85,11 @@ public function form(array $form, array &$form_state, EntityInterface $menu) {
*/
public function save(array $form, array &$form_state) {
$menu = $this->getEntity($form_state);
$system_menus = menu_list_system_menus();
if (!$menu->isNew() || isset($system_menus[$menu->id()])) {
menu_overview_form_submit($form, $form_state);
}
if ($menu->isNew()) {
// Add 'menu-' to the menu name to help avoid name-space conflicts.
......
......@@ -47,13 +47,8 @@ public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
$uri = $entity->uri();
$operations['list'] = array(
'title' => t('list links'),
'href' => $uri['path'],
'options' => $uri['options'],
'weight' => 0,
);
$operations['edit']['title'] = t('edit menu');
$operatuins['edit']['href'] = $uri['path'];
$operations['add'] = array(
'title' => t('add link'),
'href' => $uri['path'] . '/add',
......
......@@ -104,14 +104,14 @@ function addCustomMenuCRUD() {
$menu->save();
// Assert the new menu.
$this->drupalGet('admin/structure/menu/manage/' . $menu_name . '/edit');
$this->drupalGet('admin/structure/menu/manage/' . $menu_name);
$this->assertRaw($label, 'Custom menu was added.');
// Edit the menu.
$new_label = $this->randomName(16);
$menu->set('label', $new_label);
$menu->save();
$this->drupalGet('admin/structure/menu/manage/' . $menu_name . '/edit');
$this->drupalGet('admin/structure/menu/manage/' . $menu_name);
$this->assertRaw($new_label, 'Custom menu was edited.');
}
......@@ -242,10 +242,10 @@ function doMenuTests($menu_name) {
$this->disableMenuLink($item1);
$edit = array();
// Note in the UI the 'mlid:x[hidden]' form element maps to enabled, or
// NOT hidden.
$edit['mlid:' . $item1['mlid'] . '[hidden]'] = TRUE;
$this->drupalPost('admin/structure/menu/manage/' . $item1['menu_name'], $edit, t('Save configuration'));
// Note in the UI the 'links[mlid:x][hidden]' form element maps to enabled,
// or NOT hidden.
$edit['links[mlid:' . $item1['mlid'] . '][hidden]'] = TRUE;
$this->drupalPost('admin/structure/menu/manage/' . $item1['menu_name'], $edit, t('Save'));
// Verify in the database.
$this->assertMenuLink($item1['mlid'], array('hidden' => 0));
......
......@@ -7,6 +7,7 @@
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\system\Plugin\Core\Entity\Menu;
use Drupal\Component\Utility\NestedArray;
/**
* Menu callback which shows an overview page of all the custom menus and their descriptions.
......@@ -47,20 +48,35 @@ function menu_menu_edit(Menu $menu) {
}
/**
* Form for editing an entire menu tree at once.
* 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.
*/
function menu_overview_form($form, &$form_state, $menu) {
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') . '/menu.admin.css');
$sql = "
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, m.description_callback, m.description_arguments, 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->id()), array('fetch' => PDO::FETCH_ASSOC));
$result = db_query($sql, array(':menu' => $form_state['menu']->id()), array('fetch' => PDO::FETCH_ASSOC));
$links = array();
foreach ($result as $item) {
$links[] = $item;
......@@ -74,20 +90,23 @@ function menu_overview_form($form, &$form_state, $menu) {
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['#menu'] = $menu;
$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')));
if (element_children($form)) {
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
'#button_type' => 'primary',
);
}
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']->id() .'/add')));
}
return $form;
}
......@@ -183,15 +202,24 @@ function _menu_overview_tree_form($tree, $delta = 50) {
*
* @see menu_overview_form()
*/
function menu_overview_form_submit($form, &$form_state) {
function menu_overview_form_submit($complete_form, &$form_state) {
// Form API supports constructing and validating self-contained sections
// within forms, but does not allow to handle the form section's submission
// equally separated yet. Therefore, we use a $form_state key to point to
// the parents of the form section.
$parents = $form_state['menu_overview_form_parents'];
$input = NestedArray::getValue($form_state['input'], $parents);
$form = &NestedArray::getValue($complete_form, $parents);
// 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.
// are sent, ensuring parents are saved first, then their children.
// See http://drupal.org/node/181126#comment-632270
$order = array_flip(array_keys($form_state['input'])); // Get the $_POST order.
$form = array_intersect_key(array_merge($order, $form), $form); // Update our original form with the new order.
$order = array_flip(array_keys($input));
// Update our original form with the new order.
$form = array_intersect_key(array_merge($order, $form), $form);
$updated_items = array();
$fields = array('weight', 'plid');
......@@ -219,7 +247,6 @@ function menu_overview_form_submit($form, &$form_state) {
$item['customized'] = 1;
menu_link_save($item);
}
drupal_set_message(t('Your configuration has been saved.'));
}
/**
......@@ -272,6 +299,7 @@ function theme_menu_overview_form($variables) {
if (empty($rows)) {
$rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '7'));
}
$output .= drupal_render($form['inline_actions']);
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'menu-overview')));
$output .= drupal_render_children($form);
return $output;
......
......@@ -99,36 +99,28 @@ function menu_menu() {
'file' => 'menu.admin.inc',
);
$items['admin/structure/menu/manage/%menu'] = array(
'title' => 'Customize menu',
'page callback' => 'drupal_get_form',
'page arguments' => array('menu_overview_form', 4),
'title' => 'Edit menu',
'page callback' => 'menu_menu_edit',
'page arguments' => array(4),
'title callback' => 'entity_page_label',
'title arguments' => array(4),
'access arguments' => array('administer menu'),
'file' => 'menu.admin.inc',
);
$items['admin/structure/menu/manage/%menu/list'] = array(
'title' => 'List links',
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
// Not officially a local action, but displayed as such in
// menu_overview_form().
$items['admin/structure/menu/manage/%menu/add'] = array(
'title' => 'Add link',
'page callback' => 'drupal_get_form',
'page arguments' => array('menu_edit_item', 'add', NULL, 4),
'access arguments' => array('administer menu'),
'type' => MENU_LOCAL_ACTION,
'file' => 'menu.admin.inc',
);
$items['admin/structure/menu/manage/%menu/edit'] = array(
'title' => 'Edit menu',
'page callback' => 'menu_menu_edit',
'page arguments' => array(4),
'access arguments' => array('administer menu'),
'type' => MENU_LOCAL_TASK,
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => 'menu.admin.inc',
);
$items['admin/structure/menu/manage/%menu/delete'] = array(
'title' => 'Delete menu',
......
......@@ -112,6 +112,7 @@ function testBreadCrumbs() {
'admin/structure/menu' => t('Menus'),
);
$this->assertBreadcrumb('admin/structure/menu/manage/tools', $trail);
$this->assertBreadcrumb('admin/structure/menu/manage/tools/edit', $trail);
$mlid_node_add = db_query('SELECT mlid FROM {menu_links} WHERE link_path = :href AND module = :module', array(
':href' => 'node/add',
......@@ -121,7 +122,6 @@ function testBreadCrumbs() {
'admin/structure/menu/manage/tools' => t('Tools'),
);
$this->assertBreadcrumb("admin/structure/menu/item/$mlid_node_add/edit", $trail);
$this->assertBreadcrumb('admin/structure/menu/manage/tools/edit', $trail);
$this->assertBreadcrumb('admin/structure/menu/manage/tools/add', $trail);
// Verify Node administration breadcrumbs.
......
......@@ -74,13 +74,13 @@ function testDisabledAccountLink() {
// Verify that the 'My account' link is enabled.
$this->drupalGet('admin/structure/menu/manage/account');
$this->assertFieldChecked('edit-mlid2-hidden', "The 'My account' link is enabled by default.");
$this->assertFieldChecked('edit-links-mlid2-hidden', "The 'My account' link is enabled by default.");
// Disable the 'My account' link.
$edit = array(
'mlid:2[hidden]' => FALSE,
'links[mlid:2][hidden]' => FALSE,
);
$this->drupalPost('admin/structure/menu/manage/account', $edit, t('Save configuration'));
$this->drupalPost('admin/structure/menu/manage/account', $edit, t('Save'));
// Get the homepage.
$this->drupalGet('<front>');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment