Problem/Motivation

Starting in Drupal 8.5, menu editing regressed: if you add a menu link from the "add link" form, you are redirected back to the menu list, rather than the currently-selected menu. It is very jarring. This is a regression from previous 8.4.x behaviour that was introduced by #2767857: Add destination to edit, delete, enable, disable links in entity list builders.

Steps to reproduce the issue:

  1. Install standard and login
  2. Go to admin/structure/menu
  3. Click on any edit menu
  4. Click on add link
  5. Fill out the add link form and press save

A user would expect to return to the menu with its list of links. Actually, you return to the list of menus.

#2957953-43: Editing menus user-experience has regressed provides additional detail on the use-cases where this destination parameter is applied.

Proposed resolution

Remove the destination as we did in #2940165: [regression] Cannot add effects to image style via the UI.

Completed tasks

Remaining tasks

  • Confirm and deploy, pending any additional review/feedback.

User interface changes

The destination is removed from the links on admin/structure/menu

API changes

None

Data model changes

None

CommentFileSizeAuthor
#139 2957953-9.3.x-139.patch6.9 KBalexpott
#139 133-139-interdiff.txt2.56 KBalexpott
#135 menu.mp41.18 MBvikashsoni
#134 2957953-131-134-interdiff.txt778 bytesjoegraduate
#134 2957953-134-9-2-x.patch7.28 KBjoegraduate
#133 reroll_diff_2957953_130-133.txt2.72 KBankithashetty
#133 2957953-133.patch6.69 KBankithashetty
#131 2957953-9.2.x-131.patch7.28 KBjoegraduate
#130 interdiff-2957953-127-130.txt1.13 KBmohit_aghera
#130 2957953-130.patch6.66 KBmohit_aghera
#127 2957953-127.patch7.25 KBdhirendra.mishra
#123 2957953-123.patch7.25 KBseanb
#122 After Patch Menus _ drupal9-3 (1).mp42.11 MBchetanbharambe
#122 Before Patch Menus _ drupal9-3.mp43.01 MBchetanbharambe
#121 2957953-9.1.8-121.patch7.25 KBbappa.sarkar
#114 2957953-after.mp41.64 MBabhijith s
#114 2957953-before.mp41.43 MBabhijith s
#113 2957953-9.2.x-113.patch7.22 KBalexpott
#113 107-113-interdiff.txt1.09 KBalexpott
#110 2957953-9.1.x-110.patch7.21 KBbappa.sarkar
#107 2957953-9.2.x-106.patch7.24 KBalexpott
#107 104-106-interdiff.txt1.36 KBalexpott
#104 interdiff_102-104.txt1.28 KBkishor_kolekar
#104 2957953-104.patch7.26 KBkishor_kolekar
#102 interdiff-2957953-99-102.txt1.44 KBacbramley
#102 2957953-102.patch7.26 KBacbramley
#99 2957953-9.2.x-99.patch7.29 KBalexpott
#99 97-99-interdiff.txt1.08 KBalexpott
#97 2957953-9.2.x-97.patch7.28 KBalexpott
#97 92-97-interdiff.txt1.38 KBalexpott
#95 interdiff_92-95.txt518 byteskishor_kolekar
#95 2957953-9.2.x-95.patch7.27 KBkishor_kolekar
#92 2957953-9.2.x-92.patch7.27 KBalexpott
#92 90-92-interdiff.txt1.07 KBalexpott
#90 2957953-9.2.x-90.patch7.26 KBalexpott
#90 65-90-interdiff.txt3.2 KBalexpott
#88 Screenshot 2020-11-03 at 6.37.46 PM.png35.88 KBanmolgoyal74
#86 interdiff-2957953-79-86.txt2.8 KBmohit_aghera
#86 2957953-86.patch4.21 KBmohit_aghera
#80 menu_destination.patch649 bytesbatkor
#79 2975407-17.patch1.68 KBpaulocs
#65 drupal_2957953-65.patch5.71 KBsleitner
#62 interdiff-57-62.diff1.72 KBsleitner
#62 drupal_2957953-62.patch6.17 KBsleitner
#58 Before.gif1.87 MBpriyanka.sahni
#58 After.gif6.26 MBpriyanka.sahni
#55 drupal_2957953-55.patch8.61 KBsleitner
#54 drupal_2957953-54.patch8.61 KBsleitner
#52 interdiff-42-52.diff1.8 KBsleitner
#52 drupal_2957953-52.patch6.95 KBsleitner
#42 2957953-2-42.patch5.15 KBalexpott
#29 2957953-29.patch3.54 KBpobster
#29 2957953-29.test-only.patch2.68 KBpobster
#25 2957953-25.patch3.55 KBpobster
#25 2957953-25.test-only.patch2.69 KBpobster
#23 2957953-23.patch1.18 KBpobster
#20 2957953-20-interdiff.txt1.87 KBberdir
#20 2957953-20.patch6.15 KBberdir
#17 2957953-17.patch4.71 KBberdir
#16 2957953-16.patch4.98 KBberdir
#14 2957953-14.test-only.patch1.83 KBberdir
#11 2957953-9.patch1.87 KBalexpott
#11 2957953-9.test-only.patch1.13 KBalexpott
#11 8-9-interdiff.txt1.38 KBalexpott
#8 2957953-8.patch2.14 KBalexpott
#8 2957953-8.test-only.patch1.4 KBalexpott
#2 2957953-2.patch1.02 KBalexpott

Issue fork drupal-2957953

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB

Discussed a bit with @berdir who pointed out that this is not the same as #2940165: [regression] Cannot add effects to image style via the UI because there we had a form button. Here we are dealing with stuff like:

          // Bring the user back to the menu overview.
          $operations['edit']['query'] = $this->getDestinationArray();

This code no longer works because in RedirectDestination we're doing:

 public function get() {
    if (!isset($this->destination)) {
      $query = $this->requestStack->getCurrentRequest()->query;
      if (UrlHelper::isExternal($query->get('destination'))) {
        $this->destination = '/';
      }
      elseif ($query->has('destination')) {
        $this->destination = $query->get('destination');
      }
      else {
        $this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::filterQueryParameters($query->all())]);
      }
    }

    return $this->destination;
  }

So the added destination is now overriding the destination that was being generated from current.

Status: Needs review » Needs work

The last submitted patch, 2: 2957953-2.patch, failed testing. View results

berdir’s picture

Status: Needs work » Active

As discussed, I suggested to simply explicitly set query to ['destination' => $current_path] and not bother with the service as we I think explicitly only want the fallback behavior of the redirect destination service.

berdir’s picture

Status: Active » Needs work
alexpott’s picture

@Berdir I tried that but compared with #2 this doesn't fix the local task to add a new menu item :(

alexpott’s picture

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.4 KB
new2.14 KB

Here's a patch with a less complex fix and also a test that shows how broken things are. Need a more elegant way to click the right link on the menu overview page.

The last submitted patch, 8: 2957953-8.test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 8: 2957953-8.patch, failed testing. View results

alexpott’s picture

StatusFileSize
new1.38 KB
new1.13 KB
new1.87 KB

Here's a better test.

alexpott’s picture

Status: Needs work » Needs review
runeasgar’s picture

  1. Starting by confirming undesirable behavior. Confirmed. Basically, I went to /admin/structure/menu/manage/main?destination=/admin/structure/menu and then to /admin/structure/menu/manage/main/add?destination=/admin/structure/menu, and after adding my link, it returned me to /admin/structure/menu. Also agreed this is jarring.
  2. Applying patch: $ curl -l https://www.drupal.org/files/issues/2018-04-19/2957953-9.patch | git apply -v
  3. Applied clean.
  4. drush cr
  5. Redoing my test from step 1: mmm nope, same behavior. Either I'm testing in the wrong place, or this patch isn't working. Or, maybe there's some caching here that I'm not properly clearing.
  6. Taking a look at this statement from the description "The destination is removed from the links on admin/structure/menu": ok, this is even weirder behavior. Testing this scenario (adding a link using the dropdown) leaves me on the menu item afterwards (/admin/structure/menu/item/3/edit).

So.. I don't think this is fixed, and I think I also uncovered a similar undesirable behavior, in a different location, in my step 1.

Not sure I'm testing this right, so leaving issue status as-is.

berdir’s picture

StatusFileSize
new1.83 KB

Yes, what @runeasgar said :)

Also, the test-only patch did not actually fail.

The reason is that you picked an empty menu in your test and your test doesn't have the local actions (not tasks) block, the only "add link" is the empty table message. And that empty table message already does exactly what I suggested we should do also in the local actions plugin: It *specifically* links back the destination to the menu edit form.

And because that's not enough fun, we also have cacheablity metadata bugs in \Drupal\menu_ui\Plugin\Menu\LocalAction\MenuLinkAdd, because without clearing the render cache right above the test, we see a render cached local actions block that does have the "correct" destination because it's from a previous request.

So this actually does fail, but it's pretty fragile, but it's just a test-only patch. Working proper fixes...

Status: Needs review » Needs work

The last submitted patch, 14: 2957953-14.test-only.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new4.98 KB

This test does not fail on its own due to the caching issue, but I don't think we should keep a cache clear to work around a bug that no longer exists with this implementation. I think it does sufficiently prove that things are working?

berdir’s picture

StatusFileSize
new4.71 KB

Without the now unnecessary use.

alexpott’s picture

Status: Needs review » Needs work

It's not just the MenuLinkAdd though. It is also the edit button on custom links you've already added.

If you:

  1. add a menu link to a menu
  2. go back to the menu listing page
  3. click on the edit link for the menu you added the link to
  4. click on the edit link for the menu link you just added
  5. press save
  6. it'll go to the wrong place.
alexpott’s picture

+++ b/core/modules/menu_ui/src/MenuForm.php
@@ -132,6 +132,9 @@ public function form(array $form, FormStateInterface $form_state) {
+      // Prevent an existing destination parameter from interfering with the
+      // redirects added to the "Add link" and "Edit" buttons.
+      $this->getRedirectDestination()->set(NULL);

Basically. This has to stay too

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new6.15 KB
new1.87 KB

Hm. Missed that part.

If you go to admin/content?destination=/front then editing a node and saving will redirect you back to /front.

Maybe instead of dropping the query argument, we should prevent it from being added to the edit links for menus then? This page after all is very simlar to taxonomy term pages, the main difference is that the term overview there is not attached to the edit form but a separate page, so it doesn't get the default destination argument.

I still think it makes sense to keep the other improvements to have consistency between the the two add links.

I also noticed there is a third add link on the menu operations, without any destination, which means you end up on the edit form after saving, which honestly doesn't really make sense to me. But not sure where it should go instead and I think we're doing enough already here.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/menu_ui/src/Tests/MenuTest.php
@@ -258,15 +262,39 @@ public function deleteCustomMenu() {
+

This will cause a coding standards fail.

+++ b/core/modules/menu_ui/src/MenuListBuilder.php
@@ -45,10 +45,13 @@ public function getDefaultOperations(EntityInterface $entity) {
+      // Override the edit URL to not have the destination query parameter.
+      $operations['edit']['url'] = $entity->toUrl('edit-form');
+
       $operations['add'] = [
         'title' => t('Add link'),
         'weight' => 20,
-        'url' => $entity->urlInfo('add-link-form'),
+        'url' => $entity->toUrl('add-link-form'),

This solves the regression because it removes the desintation. I think we should probably do the other changes in another issue.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pobster’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB

Would love to get this moving along again?

alexpott’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@pobster an automated test would be great. That way we'll not break this again. The patch in #20 had some tests. Given that we've scoped the patch to only solve the problem they might need some adjusting.

pobster’s picture

StatusFileSize
new2.69 KB
new3.55 KB

Sure! Although ... I kinda went specific with the tests, let me know what you think?

pobster’s picture

Status: Needs work » Needs review

Okay ... that was unexpected ... failed due to the base path? I'll revisit this later.

The last submitted patch, 25: 2957953-25.test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 25: 2957953-25.patch, failed testing. View results

pobster’s picture

Status: Needs work » Needs review
StatusFileSize
new2.68 KB
new3.54 KB

Although ... might just be a quick fix... Removing the toString on the failing line, it shouldn't have made any difference ~ but there's an existing test below doing the same thing without it that I didn't spot previously.

borisson_’s picture

The fail in #25 is probably because the testbot runs from a subdirectory. In any case, the test in #29 is not working.

It also passes without the code to fix it, so the test looks like it is not specific enough.
It looks like the patch is correct though.

borisson_’s picture

Status: Needs review » Needs work

Ugh, meant change the status in my previous comment.

pobster’s picture

Status: Needs work » Closed (duplicate)

Duplicated by https://www.drupal.org/project/drupal/issues/3019834 (which is now merged with the same fix).

pobster’s picture

hudri’s picture

Status: Closed (duplicate) » Active

Changed status back to open, the "duplicate" tag is incorrect. The referenced issue 3019834 was published in v8.7, but does NOT contain this fix, the bug still exists in v8.7.6

pobster’s picture

Status: Active » Postponed (maintainer needs more info)

@hudri This hasn't regressed, I've just quickly checked it now. Please can you describe in detail the steps you're taking?

E.g.

1. Started on /admin/structure/menu
2. Clicked to edit the "Management" menu, URL contains a destination; /admin/structure/menu/manage/admin?destination=/admin/structure/menu
3. Clicked to edit a menu item, noting the URL now has no destination; /admin/structure/menu/link/entity.context.collection/edit (the lack of a destination is the "fix")
4. Saved the menu item, redirected back to the "Management" menu as expected

https://www.drupal.org/files/issues/2018-12-23/entity-url-methods-301983...

diff --git a/core/modules/menu_ui/src/MenuListBuilder.php b/core/modules/menu_ui/src/MenuListBuilder.php
index b694c8b937..c6efe07222 100644
--- a/core/modules/menu_ui/src/MenuListBuilder.php
+++ b/core/modules/menu_ui/src/MenuListBuilder.php
@@ -48,7 +48,7 @@ public function getDefaultOperations(EntityInterface $entity) {
       $operations['add'] = [
         'title' => t('Add link'),
         'weight' => 20,
-        'url' => $entity->urlInfo('add-link-form'),
+        'url' => $entity->toUrl('add-link-form'),
       ];
     }

Maybe for your circumstances, something else is causing it? Else, maybe I've just forgotten exactly what this covered!

pobster’s picture

Status: Postponed (maintainer needs more info) » Active

Hmmmm you know what?... You're right, it's just that it's the "Add link" which is broken and not the edit functionality. I swear this was working previously and oddly if you change the test to actually click the link rather than go directly to the page (i.e. so there's no "destination") the tests actually still pass...

/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php

  /**
   * Tests menu functionality.
   */
  public function doMenuTests() {
    $menu_name = $this->menu->id();

    // Test the 'Add link' local action.
    $this->drupalGet('admin/structure/menu');
    $this->xpath('//ul[@class="dropbutton"]/li/a[contains(@href,"' . $this->menu->id() . '")]')[0]->click();
    $destination = 'admin/structure/menu';
    $this->assertUrl(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name], ['query' => ['destination' => $destination]]));

    $this->clickLink(t('Add link'));
    // Ensure query destination is set.
    $destination = Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name])->toString();
    $this->assertUrl(Url::fromRoute('entity.menu.add_link_form', ['menu' => $menu_name], ['query' => ['destination' => $destination]]));

Not entirely sure I understand, as /core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php suggest that carrying over the "destination" is intentional?

hudri’s picture

@Pobster, I noticed there is an additional, hidden (caching?) quirks with the destination parameter: The backlink / destination parameter is correct on the very first visit after creating a new menu, but is incorrect after a cache clear:

  1. Start on /admin/structure/menu
  2. Click on "Add menu", create and save a new menu called "foo"
  3. You'll be redirected to /admin/structure/menu/manage/foo (without any destination parameter). Now every link regaring menu items in there (the local action "Add" button, the inline "Add" link if the menu is empty, and the "edit" button on existing items) is correctly using the destination parameter ?destination=/admin/structure/menu/manage/foo
  4. Clear all caches, e.g. do a drush cr
  5. Visit /admin/structure/menu and click the edit button of the "foo" menu
  6. The URL shows /admin/structure/menu/manage/foo?destination=/admin/structure/menu. Now the destination parameter is no longer correct on the "Add" and "Edit" menu item buttons, instead of the expected ?destination=/admin/structure/menu/manage/foo there now is an incorrect ?destination=/admin/structure/menu.
  7. Note though that the "Add" link (the inline link inside the drag table, only visible if the menu is empty) always has the correct ?destination=/admin/structure/menu/manage/foo, even after a cache clear
liquidcms’s picture

Just making sure I am on the same page; just tried this with 8.7.9 and the issue remains. Destination set when editing a menu item is: admin/structure/menu - which is wrong.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andypost’s picture

Looks all list builders affected by caching of destination links...

alexpott’s picture

Issue summary: View changes

Add steps to reproduce the issue to the issue summary and confirmed the bug still exists in D8.9

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new5.15 KB

Rerolled and added the deprecated service property trait.

ryan.ryan’s picture

Alright, so after applying the patch to 8.8.1 (cleanly), it appears the functionality is still off. Below are my test cases:

Creating a menu link from the Add link dropdown
1. From /admin/structure/menu, I click the Main Menu dropdown and click Add Link.
2. I am directed to the menu entity form, populate the fields, and submit the form.
3. The form saves and I am redirected to the (same) newly created menu entity form.

Actual result: After creating a menu link entity, I'm on the menu link entity form.
Expected result: After creating a menu link entity, I am redirected back to the Main Menu link listing.

Editing an existing menu link
1. From /admin/structure/menu, I click the edit link for the Main Menu and then click edit on an existing menu link.
2. I edit the existing menu entity and submit the form.
3. I am redirected back to /admin/structure/menu.

Actual result: After editing a menu link entity, I'm redirected back to the menu listing.
Expected result: After editing a menu link entity, I am redirected back to the Main Menu link listing.

Notes
I can see that the ?destination=/en/admin/structure/menu destination parameter persists when clicking the edit link for a menu from /admin/structure/menu. That explains why editing menu links sends you back to the menu listing. For menus, I don't really see a use-case for being redirected back to the list of menus in any scenario. In my mind, it seems extremely rare to finish editing a menu and then want to edit other menus.

Anyway, just wanted to add that testing feedback!

ryan.ryan’s picture

Status: Needs review » Needs work

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

alexpott credited larowlan.

alexpott credited shimpy.

alexpott’s picture

sleitner’s picture

Status: Needs work » Needs review
StatusFileSize
new6.95 KB
new1.8 KB

@ryan.gibson: Creating a menu link from the Add link dropdown and Editing an existing menu link now works

alexpott’s picture

Status: Needs review » Needs work

@sleitner can you add some test coverage to prove that adding /editing and deleting works. The test coverage so far only tests the Adding and editing. Plus it doesn't cover the changes you've made in #52.

sleitner’s picture

Status: Needs work » Needs review
StatusFileSize
new8.61 KB

Five additional destination tests: Add Link and Edit Menu on /admin/structure/menu and Add Link, Edit and Delete on menu link list.

sleitner’s picture

StatusFileSize
new8.61 KB
priyanka.sahni’s picture

Assigned: Unassigned » priyanka.sahni
alexpott’s picture

Issue tags: -Needs tests
StatusFileSize
new6.4 KB

I wonder if rather than doing all this changing of the destination we should adopt the solution in #2975407: After adding, deleting or editing a menu item, I am redirected to the Menus Management page rather than returned to the Menu Edit page.

Here's a patch that combines the fix from that issue with the tests from this issue and expands the tests to be test the URL the menu administrator is on rather than what the links are. It also adds testing for adding a link to menu directly from a menu page. Atm this patch makes you return to the listing the page but it is debatable what the correct place to go here is. ATM in head this operation is very weird. You get stuck on the menu item edit page!!! So we need to make a choice about where the user would rather be after adding a link directly from the menu listing page. I've left @todos for this.

There's no interdiff with #55 because the approach is different. But at least we now have pretty full test coverage of clicking around the menu UI.

Sorry @priyanka.sahni I was working on this from before I saw your comment.

priyanka.sahni’s picture

Issue tags: +menu
StatusFileSize
new6.26 MB
new1.87 MB

Verified and tested by applying patch#55.It looks good to me.Can be moved to RTBC.

Steps to test -
1. Go to the admin site.
2. Go to admin/structure/menu
3. Click on any edit menu
4. Click on add link
5. Fill out the add link form and press save
6. Verify , it should re-directs to the link listing page instead of menu listing page.

Before Patch -
BeforePatch

After Patch -
After Patch

priyanka.sahni’s picture

Assigned: priyanka.sahni » Unassigned

@alexpott I tested the patch #55.I have already posted my comment.

alexpott’s picture

@priyanka.sahni if you could review #57 and confirm if has the same impact that.d be great. It's a slightly different solution which ends up being a bit neater.

sleitner’s picture

Assigned: Unassigned » sleitner
sleitner’s picture

Assigned: sleitner » Unassigned
StatusFileSize
new6.17 KB
new1.72 KB

@alexpott #57 works as expected. My opinion is that the destination should be set to the menu page, because of two reasons:

  • I would like to see the result of the operation, especially because in most cases you have to controll the position in the menu (except you have all weight values of all other menu items in mind)
  • More often you add many items to one menu, not one item after another to many menus

The patch changes this. Please review.

jlongbottom’s picture

#62 works great for me

pobster’s picture

#62 needs work. This is now unused and can be removed (assuming the changes are good);

+  /**
+   * {@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.
+    if ($url->getRouteName() === 'entity.menu.edit_form') {
+      return $url;
+    }
+    return parent::ensureDestination($url);
+  }
sleitner’s picture

StatusFileSize
new5.71 KB

removed

function ensureDestination(Url $url)

, please review

sleitner’s picture

Nobody wants to push this problem? Does nobody use the menu UI and is annoyed by the extra clicks on every menu entry?

#65 implements the solution and tests from @alexpott , but sets the destination to the menu page /admin/structure/menu/manage/{menuid} to ensure that you can control your results in the hierarchy and the menu order. Most users will add many items to one menu, not one item after another to many menus.

acbramley’s picture

I agree with #57 it definitely makes sense to me to be taken to the place where you're managing the menu's links after adding a new one.

The interdiff between #57 and #65 looks good to me and confirmed that #65 only removed the ensureDestination function.

This is good for RTBC in my opinion! I believe @pameeela is doing some manual testing so will wait for that before changing status :)

acbramley’s picture

Issue tags: +Bug Smash Initiative

Adding bugsmash tag.

acbramley’s picture

Status: Needs review » Needs work

So I went and did some manual testing in order to update the IS as currently the User interface changes section is incorrect.

There is still one way in which this patch doesn't fix the issue.

Steps to reproduce:
1) Navigate to admin/structure/menu
2) Click Edit menu on one of the menus
3) Notice you now have a destination parameter to /admin/structure/menu
4) The Add Link button now has the destination parameter too
5) This is now cached so navigating directly to /admin/structure/menu/manage/FOO will also have the Add link button with the incorrect destination
6) Clearing cache and visiting /admin/structure/menu/manage/FOO directly will fix it.

I'll look at adding a failing test case for this.

andypost’s picture

Also needs work for comment #40

acbramley’s picture

+++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
@@ -281,21 +296,46 @@ public function deleteCustomMenu() {
+    // Test the 'Add link' local action.

So I was confused how the asserts following this were passing with my comments above but I may have found out why.

When we click Add link here there are no other menu links in the page so it's highly likely it's clicking the "Add link" link inside the empty text in the table. From my manual testing, the link inside the empty text has the correct destination however I cannot reproduce this in a test run. BUT I can reproduce it via simplytestme. I'm wondering now if there's something weird with caching on drupalci because I've had similar issues getting other tests to fail caching bugs e.g https://www.drupal.org/project/workbench_access/issues/3172841#comment-1...

paulocs’s picture

Should we not move this issue to the 9.1.x branch?

I think be redirected to the /admin/structure/menu after add a new link is really a problem.
I try to add the same approach from #65 to the 9.1.x branch but I'm still been redirected to the /admin/structure/menu page.
I didn't create a patch to the 9.1.x branch because I would like to know if we have to work on this issue on the 8.9.x or 9.1.x branch.

maosmurf’s picture

Patch #12 from https://www.drupal.org/project/drupal/issues/2975407 does solve all issues for us.

Patches #57 and #65 here do not solve the edit-links, as stated above.

batkor’s picture

maosmurf thanks your right.
This patch worked for me Drupal 9.2.0-dev

pameeela credited Webbeh.

pameeela credited ddhuri.

pameeela’s picture

@batkor, can you please upload the patch from that issue? I have closed #2305353: Make redirect after saving a menu link into another parent menu, go to the parent menu admin form as a duplicate to avoid any further duplication of effort.

I am also transferring credit from that issue for when this gets fixed.

paulocs’s picture

batkor’s picture

StatusFileSize
new649 bytes

Last worked patch for this issues
And i think this my patch not best practical.
+1 vote to use patch #79

paulocs’s picture

Issue tags: +Needs tests

We need now write tests for patch #79.

add more test coverage of deleting and editing a menu-link via the UI so we can be sure that everything behaves as we'd like.

paulocs’s picture

I'm not sure how write tests for patch #79. If someone has any tip, please tell me.

andypost’s picture

paulocs’s picture

The tests in #2975407: After adding, deleting or editing a menu item, I am redirected to the Menus Management page rather than returned to the Menu Edit page don't cover what we want. The test is already in patch #79 but it only ensures that it will not be redirected to '/admin/structure/menu'.
I think we need to write test to ensure that the page is redirected to the correct page.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new4.21 KB
new2.8 KB

Adding test cases for the patch mentioned in #79

Status: Needs review » Needs work

The last submitted patch, 86: 2957953-86.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new35.88 KB

Tests passed locally. Triggering test again.

alexpott’s picture

Status: Needs review » Needs work

It's the assertion... 1) Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuAddLinkRedirects
Behat\Mink\Exception\ExpectationException: Current page is "/subdirectory/admin/structure/menu/manage/tools", but "/admin/structure/menu/manage/tools" expected.

DrupalCI runs in a subdirectory.

Can we go back to the patch in #65. It works apart from #69 / #70

There are probably things fixed in #65 which are not addressed by #79

alexpott’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.2 KB
new7.26 KB

Here's a patch that builds on #65 to solve #69 by using the fix from #79.

It also has a test for #69.

The interdiff is back to #65

Status: Needs review » Needs work

The last submitted patch, 90: 2957953-9.2.x-90.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.07 KB
new7.27 KB

Fix the test on DrupalCI... hopefully.

Status: Needs review » Needs work

The last submitted patch, 92: 2957953-9.2.x-92.patch, failed testing. View results

andypost’s picture

+++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
@@ -100,7 +104,7 @@ protected function setUp(): void {
-  public function testMenu() {
+  public function testMenuMain() {

nit - why not testMainMenu()?
this test class already has testSystemMenuRename()

kishor_kolekar’s picture

Version: 8.9.x-dev » 9.2.x-dev
Status: Needs work » Needs review
StatusFileSize
new7.27 KB
new518 bytes

Worked on comment #94

Status: Needs review » Needs work

The last submitted patch, 95: 2957953-9.2.x-95.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB
new7.28 KB

RE #94 because it is the main menu test in this file and the rename allows the --filter option in PHPUnit to work better. It's not testing the main menu...

Fixing the test too...my regex fu--

Status: Needs review » Needs work

The last submitted patch, 97: 2957953-9.2.x-97.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.08 KB
new7.29 KB

Now tested the regex locally... lol.

acbramley’s picture

+++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
@@ -193,6 +197,16 @@ public function addCustomMenuCRUD() {
+    $this->drupalPostForm(NULL, [], t('Delete'));

@@ -281,27 +296,66 @@ public function deleteCustomMenu() {
+    $this->clickLink(t('Add link'));
+    $this->drupalPostForm(NULL, ['link[0][uri]' => '/', 'title[0][value]' => $this->randomString()], t('Save'));

IMO none of these strings should be wrapped in t(), I'm not sure if this is a standard or not but even the test changes in this patch have a mix of both.

govind.maloo’s picture

Status: Needs review » Reviewed & tested by the community

@acbramley

+++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
@@ -281,27 +296,66 @@ public function deleteCustomMenu() {
+    // Test the 'Add link' local action.
     $this->clickLink(t('Add link'));
     $link_title = $this->randomString();
     $this->drupalPostForm(NULL, ['link[0][uri]' => '/', 'title[0][value]' => $link_title], t('Save'));
     $this->assertSession()->addressEquals(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
+

This is good as we have local test separately.

acbramley’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +DrupalGov 2020
StatusFileSize
new7.26 KB
new1.44 KB

Spoke with @Sam152 about this and he agreed that patches shouldn't be adding new calls to t() in tests. There were also 2 calls to the deprecated drupalPostForm so I've fixed those up too.

paulocs’s picture

Status: Needs review » Needs work

@acbramley is right. We should not use t() in tests because we are not testing the translation.
I'm moving to needs work because patch #102 still uses drupalPostForm.
See:

+$this->drupalPostForm(NULL, ['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
and
+ $this->drupalPostForm(NULL, ['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');

kishor_kolekar’s picture

Status: Needs work » Needs review
StatusFileSize
new7.26 KB
new1.28 KB

Worked on Comment #103

Status: Needs review » Needs work

The last submitted patch, 104: 2957953-104.patch, failed testing. View results

paulocs’s picture

@kishor_kolekar you should remove NULL, from $this->submitForm(NULL, ['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save'); in both cases.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.36 KB
new7.24 KB

@kishor_kolekar when you change a test it's a really good idea to run it locally prior to uploading a patch. Also I'm not a fan of the drupalPostForm deprecation... oh well.

Here's a fix.

paulocs’s picture

Status: Needs review » Reviewed & tested by the community

I tested patch #107 and it looks good to me.
The test looks good too. Moving to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 107: 2957953-9.2.x-106.patch, failed testing. View results

bappa.sarkar’s picture

StatusFileSize
new7.21 KB

Patch for drupal 9.1.x

abhijith s’s picture

Status: Needs work » Needs review
alexpott’s picture

#110 is not a fix and only results in broken coding standards...

Here is the diff between #107 and #110

 2957953-9.2.x-bappa     git diff 2957953-9.2.x 2957953-9.2.x-bappa                                                                                      245ms  Tue  9 Feb 12:52:08 2021
diff --git a/core/modules/menu_ui/src/MenuListBuilder.php b/core/modules/menu_ui/src/MenuListBuilder.php
index 59af3090bd..9fa474bef9 100644
--- a/core/modules/menu_ui/src/MenuListBuilder.php
+++ b/core/modules/menu_ui/src/MenuListBuilder.php
@@ -65,10 +65,10 @@ public function getDefaultOperations(EntityInterface $entity) {
    * {@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;
+      // 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;
   }

   /**
diff --git a/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
index 24ccb32a5d..d1fd6f621e 100644
--- a/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
+++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
@@ -319,6 +319,7 @@ public function doMenuTests() {
     // 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();
alexpott’s picture

StatusFileSize
new1.09 KB
new7.22 KB

Here's a fix for the test failure. Interdiff back to #107 because #112.

abhijith s’s picture

StatusFileSize
new1.43 MB
new1.64 MB

Applied patch #113 on 9.2.x and it works fine.Added screen recordings.

capysara’s picture

Tested on simplytest.me following steps to reproduce 1-5 in the issue description. Works as expected: You end up back at the menu with its list of links.

Also applied patch with composer on existing site with core 9.1.3. Same results.

Thanks! This fixes something pretty annoying.

maxpah’s picture

Hello,

Tested on 9.1.4, working great, thanks for the patch.

trackleft2 made their first commit to this issue’s fork.

trackleft2’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bappa.sarkar’s picture

StatusFileSize
new7.25 KB

The patch 2957953-9.2.x-113.patch no longer applicable on 9.1.8

Updating the patch!

chetanbharambe’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.01 MB
new2.11 MB

Verified and tested patch #121.
Patch applied successfully and looks good to me.

Testing Steps:
# Goto: admin/structure/menu
# Click on any edit menu
# Click on add link
# Fill out the add link form and press save
# User should be redirected to back at the menu with its list of links but actually, the user is redirected to back at the list of menus.

Expected Results:
# User should be redirected to back at the menu with its list of links.

Actual Results:
# User is redirected to back at the list of menus.

Looks good to me.
Can be a move to RTBC.

seanb’s picture

StatusFileSize
new7.25 KB

The patch in #121 didn't seem to apply so here is another reroll for 9.1.x.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Bug fixes go against the latest version, so this needs a working patch against 9.3.x.

I read the Issue Summary and it is out of date. The remaining steps show that a test is needed but there is one in the patch. As a reviewer, that makes me wonder if the test needs more work?

I had a brief look at the patch and I want to recommend changes to a comment but I have to go now.

Webbeh’s picture

Given the last summary update was performed in #2957953-44: Editing menus user-experience has regressed, I'm updating the issue summary with where we're at.

Removing outdated issue tags to reflect the issue summary update and to remove an out-of-date conference tag.

As a friendly reminder, here's where our remaining tasks sit as of this comment (as also reflected in the summary):

Remaining tasks

Let's squash this bug!

Webbeh’s picture

Issue summary: View changes
dhirendra.mishra’s picture

StatusFileSize
new7.25 KB

Here i have re-rolled the patch against 9.3.x

mohit_aghera’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 127: 2957953-127.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new6.66 KB
new1.13 KB

Fixing the test cases and removing deprecated method.
The patch was not applicable on the latest 9.3.x head, I had to re-roll it.

joegraduate’s picture

StatusFileSize
new7.28 KB

Re-roll of last working 9.2.x patch (from #118 / #119) that should apply to latest 9.2.x branch / 9.2.x release version.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Sorry, needs a reroll.

ankithashetty’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new6.69 KB
new2.72 KB

Re-rolled the patch in #130 against the latest 9.3.x, thanks!

joegraduate’s picture

StatusFileSize
new7.28 KB
new778 bytes

Re-rolled the patch in #131 against the latest 9.2.x.

vikashsoni’s picture

StatusFileSize
new1.18 MB

applied patch #121 working fine
after patch the destination will be menu list for ref sharing

paulocs’s picture

Status: Needs review » Reviewed & tested by the community

Patch #133 looks good!

It properly redirects when deleting a menu link and when editing a menu link.
The code looks clean as well and the tests seems to cover the bug.

Cheers, Paulo.

batkor’s picture

+

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
    @@ -195,6 +199,16 @@ public function addCustomMenuCRUD() {
    +    // Click the "Add link" operation in the Tools row.
    

    This is the delete link, not the add link.

    Whilst we're here, can we add a comment saying that we're doing this via the UI so that we can test destination handling, otherwise someone might think this duplicates the existing delete test case in ::deleteCustomMenu

  2. +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
    @@ -279,11 +294,35 @@ public function deleteCustomMenu() {
    +    $link_title = $this->randomString();
    +    $this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
    ...
    +    $link_title = $this->randomString();
    +    $this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
    

    Can we also assert that the new link exists was indeed crated, e.g the link title appears on the page.

  3. +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
    @@ -300,6 +339,20 @@ public function doMenuTests() {
    +    // Clear the cache to ensure that recent caches aren't preventing us from
    +    // seeing a broken add link.
    +    $this->resetAll();
    

    I see talk above about their being a caching bug in the local actions block - is that what this is for?

    If so, is there an existing issue for that?

    If not, can we create one?

    If so, can we postpone this issue on fixing that first?

  4. +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
    @@ -300,6 +339,20 @@ public function doMenuTests() {
    +    $this->clickLink('Add link');
    +    $this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $this->randomString()], 'Save');
    

    Same here re testing that the new link was indeed created/exists on the page

alexpott’s picture

StatusFileSize
new2.56 KB
new6.9 KB

@larowlan thanks for the review.

Re #3
1. Fixed
2. Fixed - this pretty much c&p from other parts of the test but there's no harm in the additional assertions.
3. I don't think this issue should be postponed on that. This exists to ensure that our cache is not hiding a bug as it has been. I don't think this is a bug per se it ensuring that the cache is not hiding a bug. We could file a follow-up to test and ensure that caches are cleared as expected when using the menu UI.
4. Fixed

sleitner’s picture

Status: Needs review » Reviewed & tested by the community

Patch #139 looks good!

It properly redirects when deleting a menu link and when editing a menu link.
The code looks clean as well and the tests seems to cover the bug.

Webbeh’s picture

Issue summary: View changes
larowlan’s picture

Saving issue credit

  • larowlan committed 8a18762 on 9.3.x
    Issue #2957953 by alexpott, sleitner, pobster, Berdir, mohit_aghera,...

  • larowlan committed 0ab6f20 on 9.2.x
    Issue #2957953 by alexpott, sleitner, pobster, Berdir, mohit_aghera,...
larowlan’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 8a18762 and pushed to 9.3.x. Thanks!

As this is fixing a major bug and there is little risk of regression, backported to 9.2.x

Thanks everyone for the mammoth effort here

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.