Skip to content
Snippets Groups Projects
Unverified Commit 8a187621 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2957953 by alexpott, sleitner, pobster, Berdir, mohit_aghera,...

Issue #2957953 by alexpott, sleitner, pobster, Berdir, mohit_aghera, kishor_kolekar, joegraduate, trackleft2, bappa.sarkar, acbramley, ankithashetty, paulocs, batkor, dhirendra.mishra, seanB, priyanka.sahni, Abhijith S, chetanbharambe, vikashsoni, anmolgoyal74, Webbeh, larowlan, hudri, ryan.gibson, amietpatial, ddhuri, capysara, runeasgar, saranya ashokkumar, shimpy, nikitagupta: Editing menus user-experience has regressed
parent 3f0caa8a
No related branches found
No related tags found
12 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -4,6 +4,7 @@
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/**
* Defines a class to build a listing of menu entities.
......@@ -49,6 +50,9 @@ public function getDefaultOperations(EntityInterface $entity) {
'title' => t('Add link'),
'weight' => 20,
'url' => $entity->toUrl('add-link-form'),
'query' => [
'destination' => $entity->toUrl('edit-form')->toString(),
],
];
}
if (isset($operations['delete'])) {
......@@ -57,6 +61,16 @@ public function getDefaultOperations(EntityInterface $entity) {
return $operations;
}
/**
* {@inheritdoc}
*/
protected function ensureDestination(Url $url) {
// We don't want to add the destination URL here, as it means we get
// redirected back to the list-builder after adding/deleting menu links from
// a menu.
return $url;
}
/**
* {@inheritdoc}
*/
......
......@@ -85,6 +85,10 @@ protected function setUp(): void {
$this->drupalPlaceBlock('page_title_block');
$this->drupalPlaceBlock('system_menu_block:main');
$this->drupalPlaceBlock('local_actions_block', [
'region' => 'content',
'weight' => -100,
]);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
......@@ -101,7 +105,7 @@ protected function setUp(): void {
/**
* Tests menu functionality using the admin and user interfaces.
*/
public function testMenu() {
public function testMenuAdministration() {
// Log in the user.
$this->drupalLogin($this->adminUser);
$this->items = [];
......@@ -195,6 +199,16 @@ public function addCustomMenuCRUD() {
$menu->save();
$this->drupalGet('admin/structure/menu/manage/' . $menu_name);
$this->assertSession()->pageTextContains($new_label);
// Delete the custom menu via the UI to testing destination handling.
$this->drupalGet('admin/structure/menu');
$this->assertSession()->pageTextContains($new_label);
// Click the "Delete menu" operation in the Tools row.
$links = $this->xpath('//*/td[contains(text(),:menu_label)]/following::a[normalize-space()=:link_label]', [':menu_label' => $new_label, ':link_label' => 'Delete menu']);
$links[0]->click();
$this->submitForm([], 'Delete');
$this->assertSession()->addressEquals('admin/structure/menu');
$this->assertSession()->responseContains("The menu <em class=\"placeholder\">$new_label</em> has been deleted.");
}
/**
......@@ -259,6 +273,7 @@ public function deleteCustomMenu() {
$this->drupalGet("admin/structure/menu/manage/{$menu_name}/delete");
$this->submitForm([], 'Delete');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->addressEquals("admin/structure/menu");
$this->assertSession()->pageTextContains("The menu $label has been deleted.");
$this->assertNull(Menu::load($menu_name), 'Custom menu was deleted');
// Test if all menu links associated with the menu were removed from
......@@ -279,11 +294,37 @@ public function deleteCustomMenu() {
* Tests menu functionality.
*/
public function doMenuTests() {
// Add a link to the tools menu first, to test cacheability metadata of the
// destination query string.
$this->drupalGet('admin/structure/menu/manage/tools');
$this->clickLink('Add link');
$link_title = $this->randomString();
$this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
$this->assertSession()->linkExists($link_title);
$this->assertSession()->addressEquals('admin/structure/menu/manage/tools');
// Test adding a menu link direct from the menus listing page.
$this->drupalGet('admin/structure/menu');
// Click the "Add link" operation in the Tools row.
$links = $this->xpath('//*/td[contains(text(),:menu_label)]/following::a[normalize-space()=:link_label]', [':menu_label' => 'Tools', ':link_label' => 'Add link']);
$links[0]->click();
$this->assertMatchesRegularExpression('#admin/structure/menu/manage/tools/add\?destination=(/[^/]*)*/admin/structure/menu/manage/tools$#', $this->getSession()->getCurrentUrl());
$link_title = $this->randomString();
$this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
$this->assertSession()->linkExists($link_title);
$this->assertSession()->addressEquals('admin/structure/menu/manage/tools');
$menu_name = $this->menu->id();
// Test the 'Add link' local action.
$this->drupalGet(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
// Access the menu via the overview form to ensure it does not add a
// destination that breaks the user interface.
$this->drupalGet('admin/structure/menu');
// Select the edit menu link for our menu.
$links = $this->xpath('//*/td[contains(text(),:menu_label)]/following::a[normalize-space()=:link_label]', [':menu_label' => (string) $this->menu->label(), ':link_label' => 'Edit menu']);
$links[0]->click();
// Test the 'Add link' local action.
$this->clickLink('Add link');
$link_title = $this->randomString();
$this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
......@@ -300,6 +341,22 @@ public function doMenuTests() {
$this->submitForm([], 'Delete');
$this->assertSession()->addressEquals(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
// Clear the cache to ensure that recent caches aren't preventing us from
// seeing a broken add link.
$this->resetAll();
$this->drupalGet('admin/structure/menu');
// Select the edit menu link for our menu.
$links = $this->xpath('//*/td[contains(text(),:menu_label)]/following::a[normalize-space()=:link_label]', [':menu_label' => (string) $this->menu->label(), ':link_label' => 'Edit menu']);
$links[0]->click();
// Test the 'Add link' local action.
$this->clickLink('Add link');
$link_title = $this->randomString();
$this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
$this->assertSession()->linkExists($link_title);
$this->assertSession()->addressEquals(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
// Add nodes to use as links for menu links.
$node1 = $this->drupalCreateNode(['type' => 'article']);
$node2 = $this->drupalCreateNode(['type' => 'article']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment