Problem/Motivation

The 'Edit' link for custom menu links does not contain the language prefix of the current language, so it always takes you to the edit page in the default language.

Steps to reproduce

  1. Install Drupal
  2. Enable Language and Configuration translation
  3. Create a node and add a link to the main menu
  4. Switch to another language and go to the main menu admin page (e.g. /fr/admin/structure/menu)
  5. See that the 'Edit' button for the default home link points to /fr/admin/structure/menu/link/standard.front_page/edit
  6. See that the 'Edit' button for the custom link points to /admin/structure/menu/item/1/edit

Expected result would be the edit link points to /fr/admin/structure/menu/item/1/edit to reflect the current language.

Proposed resolution

Ensure that the menu edit links for custom menu items use the current language prefix.

Remaining tasks

  1. Write patch
  2. Review

User interface changes

Update the menu edit links to add the current language prefix.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cFreed created an issue. See original summary.

Version: 8.0.0 » 8.0.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.0.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. Branches prior to 8.8.x are not supported, and 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.

pameeela’s picture

Title: Inconsistent multilingual behaviour of some "Edit menu link" pages » Menu link 'Edit' does not retain the current language for custom links
Version: 8.9.x-dev » 9.1.x-dev
Component: translation.module » language system
Issue summary: View changes
Issue tags: +Bug Smash Initiative

I have updated the IS to distill this down to a simple, reproducible issue.

bbu23’s picture

Hello,

I'm providing a patch for this, but since this is a core issue, I'm not sure about the approach. I found two places where I can fix this, and chose the plugin because I thought it's more appropriate for reusability of the methods that I've updated.

The other place would have been in the \Drupal\menu_ui\MenuForm.php file

// Allow for a custom edit link per plugin.
$edit_route = $link->getEditRoute();
if ($edit_route) {
  // ----> Here I would have unset the language from the options array. <----
  $operations['edit']['url'] = $edit_route;
  // Bring the user back to the menu overview.
  $operations['edit']['query'] = $this->getDestinationArray();
}

But this second solution would apply only for the tree, so not everywhere, that's why I chose the first solution.

bbu23’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: menu_links_language-2623254-5.patch, failed testing. View results

jonathanshaw’s picture

Title: Menu link 'Edit' does not retain the current language for custom links » Menu link edit & delete routes do not retain the current language
Issue tags: +Needs tests

Your patch looks good to me @bbu23, although menu is not an area I know much about. This does need test coverage though, and I'm not sure if any test in the menu_link_content module is a good one to base the test on. There is also a test failure to fix.

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
3.04 KB
2.13 KB

Test cases for initial review.

Status: Needs review » Needs work

The last submitted patch, 9: menu_links_language-2623254-9.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
44.71 KB
40.77 KB

Looks like unrelated failure.
Triggered the test again.

Status: Needs review » Needs work

The last submitted patch, 9: menu_links_language-2623254-9.patch, failed testing. View results

chandrashekhar_srijan’s picture

Uploading a test only patch to see if it fixes the issue.

As mentioned in #11 I have this test passed on my local.

mohit_aghera’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: test-only_2623254-13.patch, failed testing. View results

quietone’s picture

I just tried to reproduce this on a minimal install of 9.1.x and failed. In step 6, the result I get is the expected result, the edit link points to
/it/admin/structure/menu/item/1/edit?destination=/it/admin/structure/menu. Since it was a minimal install there was no 'home' link to test as in step 5.

Ignore the above. I can reproduce it.

quietone’s picture

Status: Needs work » Needs review
FileSize
1.86 KB
1.59 KB
2.49 KB

Having a go at this. I made a patch with the following changes.

  1. +++ b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php
    @@ -83,6 +84,18 @@ public function testTranslationLinkOnMenuEditForm() {
    +    $menu_link_content = MenuLinkContent::create([
    

    Don't think this is needed.

  2. +++ b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php
    @@ -83,6 +84,18 @@ public function testTranslationLinkOnMenuEditForm() {
    +      ['menu_link_content' => $menu_link_content_id], ['langcode' => 'fr'])->toString());
    ...
    +      ['menu_link_content' => $menu_link_content_id], ['langcode' => 'fr'])->toString());
    

    The docs for Url::fromRoute direct to \Drupal\Core\Url::fromUri() which doesn't have a 'langcode' property. It does have a language property which is an object.

amateescu’s picture

The bug reported here is the "standard" practice throughout the whole entity system (e.g. you can observe this behavior for nodes too), so any change needs to be made on a more general level, not just for menu links.

The last submitted patch, 17: 2623254-17-fail.patch, failed testing. View results

mohit_aghera’s picture

@quietone
I've uploaded initial patch where we are modifying "getDefaultOperations()" method in EntityListBuilder class.

I was not able to use dependency injection because it will potentially affect all the classes that extends EntityListBuilder. It may affect many custom and contributed modules.
Triggering tests to evaluate all the failures and fix accordingly.

Status: Needs review » Needs work

The last submitted patch, 20: 2623254-20.patch, failed testing. View results

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
7.37 KB
3.81 KB

Status: Needs review » Needs work

The last submitted patch, 23: 2623254-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jonathanshaw’s picture

  1. +++ b/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php
    @@ -185,14 +185,16 @@ public function getDescription() {
    -    return $this->getEntity()->toUrl();
    +    $language = $this->languageManager->getCurrentLanguage();
    +    return $this->getEntity()->toUrl('edit-form', ['language' => $language]);
    

    Specifying the link type as "edit-form", when previously we used the default, seems like a significant change. Maybe I'm missing something.

  2. We should add to the test coverage in EntityListBuilderTest.
  3. IS needs updating for #18.
pameeela’s picture

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

I set this to the wrong branch, moving back.

KapilV’s picture

Assigned: Unassigned » KapilV
KapilV’s picture

Assigned: KapilV » Unassigned
Status: Needs work » Needs review
FileSize
7.47 KB
4.29 KB

Hear an updated patch.

Status: Needs review » Needs work

The last submitted patch, 28: 2623254-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
7.61 KB
1.01 KB

Fixing test case failures and adding entity creation for the menu link content entity.

Status: Needs review » Needs work

The last submitted patch, 30: 2623254-30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

codersukanta’s picture

Fixed issues in the patch.

I have tried to keep the changes restrained within scope of the issue, for this I have undo the changes at entity level files.

mohit_aghera’s picture

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

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

borisson_’s picture

I disagree with the approach taken in #32, according to @amateescu in #18 we need to do this at the entity level instead of just for menu links.

So I think the next step here is to update the issue summary to make it more generalized and then we should try to continue on the patch in #30

jonathanshaw’s picture

#37 +1

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

have to agree with #37 so moving to NW for that work.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.