Problem/Motivation

Using the Menu UI page we can override some values of the menu links provided by modules, Those values are:

  • menu_name
  • parent
  • weight
  • expanded
  • enabled

But one important value is missing, the "title" field, I don't know if there is a technical reason why the title isn't overridable but seems something which might be useful, for instance #2838106: Standard profile: make "Home" menu link to <front> editable/deletable giving the user the ability to just edit the title would fix that issue and the same happens for any menu link provided by a contrib module.

In my next comment a patch with the change.

(This will require tests which I can provide as well but I just want to know first if there is a reason why the title wasn't between these values in first place I just fixed the tests to include this new key, so not sure if we need more tests.)

Steps to reproduce

Proposed resolution

- Add the title to the schema of menu link overrides as a label data type.
- Add the title to the menu link form
- Add the title to the $overrideAllowed attribute on the menu link plugin

Remaining tasks

  • Fix broken unit test
  • Code review

User interface changes

N/A

API changes

Data model changes

N/A

Release notes snippet

TBD

Issue fork drupal-2916639

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

gnuget created an issue. See original summary.

gnuget’s picture

gnuget’s picture

Status: Active » Needs review
gnuget’s picture

Issue summary: View changes
gnuget’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 2916639-override-title-module-menu-link.patch, failed testing. View results

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new4.32 KB
new507 bytes

Forgot to add the title in the schema.

I just added it in this patch.

Status: Needs review » Needs work

The last submitted patch, 7: 2916639-override-title-module-menu-link-7.patch, failed testing. View results

gnuget’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new6.46 KB
new2.14 KB

I just fixed the two failing tests.

gnuget’s picture

Issue summary: View changes
mlncn’s picture

Status: Needs review » Reviewed & tested by the community

This is simple, powerful, and has tests!

The only reason i can think this wasn't included to start with might be internationalization support? But if you don't override, you don't lose whatever support the module might or might not be providing anyway.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/config/schema/core.menu.schema.yml
@@ -9,6 +9,9 @@ core.menu.static_menu_link_overrides:
+            type: string

I think this needs to be translatable - so should be of type label as that will enable config translation.

Also we need an upgrade path for existing configuration.

alexpott’s picture

This patch also breaks existing translations. If you:

  1. Install standard without the patch applied
  2. Enable config_transaltion
  3. Add Arabic
  4. View frontpage
  5. The contact link in the footer is translated into arabic

But if you:

  1. Install standard with the patch applied
  2. Enable config_transaltion
  3. Add Arabic
  4. View frontpage
  5. The contact link in the footer is not translated
gnuget’s picture

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new7.69 KB
new2 KB

Hi!

Thanks for the reviews Alex!

I just added the upgrade path in this new patch and changed the type to label.

Also added as related the issue #2710469: Move contact module footer link to standard install profile once we fixed that one #13 won't be a problem anymore.

Right now is a problem because the standard profile adds the footer link in the core.menu.static_menu_link_overrides.yml file in the profile installation, once we added that link as a content this won't be a problem anymore.

is there another way to make this work without the need to fix #2710469: Move contact module footer link to standard install profile first? In theory using the type "label" should pick the translation even if the value is in the yml file, yes?

thanks for your review.

Patch and interdiff atached.

(I will mark this as needs review to make sure to all is working once all the test passed I will switch it back to needs work)

Status: Needs review » Needs work

The last submitted patch, 15: 2916639-override-title-module-menu-link-15.patch, failed testing. View results

gnuget’s picture

Issue summary: View changes
StatusFileSize
new138.74 KB

I tried to fix the broken test but not sure how to fix it.

The error is:

1) Drupal\Tests\system\Functional\Update\UpdatePathWithBrokenRoutingFilledTest::testWithBrokenRouting
Behat\Mink\Exception\ExpectationException: The string "<strong>Failed:</strong>" appears in the HTML response of this page, but it should not.

And it seems that my hook_update triggers the BrokenInboundPathProcessor::processInbound which in this test it is supposed to be executed when visiting the homepage but not in the $this->runUpdates(), so not sure if I should avoid my hook_update to execute this event (rewriting it to make this change in a different manner) or if should I exclude my hook_update to run in this test.

hook update screen

alexpott’s picture

  1. +++ b/core/modules/system/system.install
    @@ -2042,3 +2042,28 @@ function system_update_8403() {
    +/**
    + * Add the titles into the static_menu_link_overrides config.
    + */
    +function system_update_8501() {
    

    Move this to be a post update - see core/modules/system/system.post_update.php. You might be using API you can't rely on in a hook_update_N

  2. +++ b/core/modules/system/system.install
    @@ -2042,3 +2042,28 @@ function system_update_8403() {
    +  $menuLinkManager = \Drupal::service('plugin.manager.menu.link');
    +  $definition = $menuLinkManager->getDefinitions();
    +
    +  /** @var Drupal\Core\Menu\StaticMenuLinkOverrides $staticOverrides */
    +  $staticOverrides = \Drupal::service('menu_link.static.overrides');
    +
    +  foreach ($definition as $plugin_id => $menu_link) {
    

    We could do less looping by doing something like:

        $overrides = $staticOverrides->loadMultipleOverrides(array_keys($definitions));
        foreach ($overrides as $id => $changes) {
    

    And no need for a continue too :)

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new2.16 KB
new7.79 KB

Hi!

Thanks again for your help Alex, I just added your suggestions to my patch.

Let's see what the testbot say.

Should I postpone this issue and work on #2710469: Move contact module footer link to standard install profile first? or is there a way where I can fix this one first?

- David.

Status: Needs review » Needs work

The last submitted patch, 19: 2916639-override-title-module-menu-link-19.patch, failed testing. View results

gnuget’s picture

oh, the same test failed again :-(

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

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

robbdavis’s picture

Bump. I just spent 1/2 an hour trying to figure out why I couldn't delete the home link. Disabling it is OK but not clean. I'm all for making it deletable.

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.

mlncn’s picture

Status: Needs work » Needs review

Wishfully hoping the testbot might have changed its mind...

Status: Needs review » Needs work

The last submitted patch, 19: 2916639-override-title-module-menu-link-19.patch, failed testing. View results

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

chris matthews’s picture

Issue tags: +DrupalWTF

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

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.

mlncn’s picture

Issue tags: +Needs reroll
spokje’s picture

Re-roll of patch #19 against 9.2.x-dev

spokje’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
sagesolutions’s picture

Can you re-roll the patch for Drupal 8?

Thanks!

sagesolutions’s picture

For now, I ended up using the hook_toolbar_alter() function


/**
 * Implements hook_toolbar_alter().
 */
function MYMODULE_toolbar_alter(&$items) {
  
  // Override titles of top level items
  $items['workbench']['tab']['#title'] = "Admin Workbench";
  $items['administration']['tab']['#title'] = "Manage Drupal";

}

See https://www.drupal.org/project/toolbar_menu/issues/2949053#comment-13998889

rosk0’s picture

Status: Needs review » Reviewed & tested by the community

Code looks good, update path is in place, tests are passing.

Manual testing went good. Tested on Drupal 9.1.4.

gauravvvv’s picture

Patch #33, Failed to apply. needs re-roll.

gauravvvv’s picture

Status: Reviewed & tested by the community » Needs work
adityasingh’s picture

Status: Needs work » Needs review
StatusFileSize
new7.77 KB

Reroll the patch for 9.2.x.

Status: Needs review » Needs work

The last submitted patch, 40: 2916639-40.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new7.79 KB
new871 bytes

Fixed syntax error.

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.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

The re-rolled and fixed patch of #42 is RTBC as per #37 and my own and others testing and use in production.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This needs to apply-able to 10.0.x and 9.4.x - as a task those are the only branches open where this can land but there are conflicts in core/lib/Drupal/Core/Menu/StaticMenuLinkOverridesInterface.php and core/tests/Drupal/Tests/Core/Menu/StaticMenuLinkOverridesTest.php

gauravvvv’s picture

StatusFileSize
new7.76 KB

I have updated the patch for D9.4, Please review.
Patch #42, is no longer applies to D9, so not able to generate interdiff for same.

gauravvvv’s picture

Status: Needs work » Needs review
gauravvvv’s picture

StatusFileSize
new7.75 KB
damienmckenna’s picture

Should this be a bug report? It's a little silly that the title isn't editable.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Returning to RTBC and triggered tests to see if any issues with 10.x and 9.5.x

quietone’s picture

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

This needs a patch that applies to 10.0.x.

The issue summary should explain the resolution here, adding tag for an is update. A fail patch would be helpful as well.

Way back in #13 it was reported that the patch changed the contact link in the footer of a standard install. Perhaps I missed it but I don't see confirmation that that has been fixed.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jweowu’s picture

Re-roll of #49 against 10.1.x.

gauravvvv’s picture

StatusFileSize
new7.8 KB

I have attached patch for 11.x

mlncn’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

#54 mentions an issue summary update which is still needed.

Have not reviewed or tested.

generalredneck’s picture

Adding a reroll for 10.3

tonibarbera’s picture

StatusFileSize
new7.83 KB

Rerolled for 10.3.1

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

akalam’s picture

Issue summary: View changes
akalam’s picture

Issue summary: View changes
Status: Needs work » Needs review

I've created a MR against 11.x and updated the summary to explain the resolution

smustgrave’s picture

MR appears to have pipeline issues

With regards to the post_update hook this something may want to use a ConfigImporter class to run in batches?

Post update hook will need test coverage too

Thanks!

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

oily’s picture

Fixed PHPSTAN and PHPCS. Pipeline has failing unit test(s).

oily’s picture

Title: Allow override the menu link titles at core.menu.static_menu_link_overrides.yml » Allow the menu link titles at core.menu.static_menu_link_overrides.yml to be overriden
Issue summary: View changes

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

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