Problem/Motivation

We currently have hard-coded hacks like this in MenuForm:

        elseif (($url = $link->getUrlObject()) && $url->isRouted() && $url->getRouteName() == 'user.page') {
          $form[$id]['title']['#suffix'] = ' (' . $this->t('logged in users only') . ')';
        }

This means contrib/custom menu links aren't able to do this without some heaving form altering.

See #2503755-86: Switch from user login block to login menu link and search block in standard profile and #2503755-87: Switch from user login block to login menu link and search block in standard profile.2.

Proposed resolution

Allow menu link plugins to specify admin labels.

Remaining tasks

TBD

User interface changes

None.

API changes

API addition.

Data model changes

None.

Issue fork drupal-2568785

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

Wim Leers created an issue. See original summary.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

joachim’s picture

Version: 8.1.x-dev » 8.2.x-dev
dawehner’s picture

Status: Active » Needs review
StatusFileSize
new6.21 KB

Are we sure we can still do that at this point in time without breaking any BC? An alternative would be to make somehow link objects aware of the fact that we render it on the admin URL at the moment.

IMHO though we already have the capability to do that, see the patch

Status: Needs review » Needs work

The last submitted patch, 4: 2568785-4.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

duaelfr’s picture

Shouldn't we introduce a new "admin_description" available in the *.links.menu.yml files?
That behavior could be used by contrib/custom developpers and seems more testable to me.

Plus, to review the patch in #4 more precisely, I think it introduces a small but unwanted change: with the patch, the link wraps the menu item title and the help text instead of only wrapping the menu item title.

dpi’s picture

More reason to remove it.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.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.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.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.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.

jacobsanford’s picture

StatusFileSize
new6.2 KB
new0 bytes

@dawehner's patch in #4 no longer applied to 8.6.x. A reroll with no further modifications is attached. Issues raised in #7 still outstanding.

Interdiff is flaky due to new file. I'll try to re-upload one tomorrow.

claudiu.cristea’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: 2568785-12.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new7.11 KB
new2.15 KB

Fixed the test and removed markup from the title because it gets encoded.

joachim’s picture

The patches don't seem to do what the issue summary (or the title!) says.

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.

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.

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.

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.

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.

solideogloria’s picture

Status: Needs review » Needs work

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.

nikhil_110’s picture

StatusFileSize
new7.25 KB

Attached patch against Drupal 10.1.x
Patch #15 is not applied for Drupal 10.1.x so Inter-diff file is not added.

Checking patch core/modules/menu_ui/src/MenuForm.php...
Hunk #1 succeeded at 234 (offset 14 lines).
error: while searching for:
      ]),
    ]);
    $links = $this->buildOverviewTreeForm($tree, $delta);
    foreach (Element::children($links) as $id) {
      if (isset($links[$id]['#item'])) {
        $element = $links[$id];

error: patch failed: core/modules/menu_ui/src/MenuForm.php:273
error: core/modules/menu_ui/src/MenuForm.php: patch does not apply
Checking patch core/modules/user/src/Plugin/Menu/LoginLogoutMenuLink.php...
Checking patch core/modules/user/src/Plugin/Menu/UserPageMenuLink.php...
Checking patch core/modules/user/tests/src/Functional/UserAccountLinksTest.php...
error: while searching for:
    // auto-increment is 1. Use XPath to obtain input element id and name using
    // the consistent label text.
    $this->drupalGet('admin/structure/menu/manage/account');
    $label = $this->xpath('//label[contains(.,:text)]/@for', [':text' => 'Enable My account menu link']);
    $this->assertFieldChecked($label[0]->getText(), "The 'My account' link is enabled by default.");

    // Disable the 'My account' link.

error: patch failed: core/modules/user/tests/src/Functional/UserAccountLinksTest.php:88
error: core/modules/user/tests/src/Functional/UserAccountLinksTest.php: patch does not apply

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.

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

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

mrinalini9’s picture

Status: Needs work » Needs review

Created MR for the patch changes in #27 for the 11.x branch, please review it.

Thanks!

smustgrave’s picture

Status: Needs review » Needs work

@mrinalini9 please don’t take patches and just turn to MRs without checking.

fix should use constructor promotion and type hints for and that’s just from 5 second glance.

Also please read the comments and tags. This was tagged for issue summary which still hasn’t happened

Thanks

sebish’s picture

We were working with colleagues on that issue and we would like to propose an alternative approach. The current patch is adding the description inside the link itself and we do not think it's the best approach.

Screenshot

What about if we use the metadata property already available in the MenuLinkFieldDefinitions.php ?
We could have user.link.menu.yml looking like:

user.page:
  title: 'My account'
  weight: -10
  route_name: user.page
  menu_name: account
  metadata:
    suffix: '(logged in users only)'

Then in the MenuForm.php, we could get the suffix property of metadata. That way, any contrib or custom module could do it the same way to display the message they want beside the menu link.

Something like this in MenuForm.php:

if ( isset($link->getMetaData()['suffix']) ) {
  $suffix = $link->getMetaData()['suffix'];
}

I'd be happy to provide with a patch if you think that's helping.

jigarius’s picture

StatusFileSize
new26.21 KB

The idea in #34 seems interesting and the description could in fact be put under the "metadata" key. However, the "metadata" property doesn't seem to have a clear description or definition of purpose. It would be good to know what that property is expected to be used for before making a decision.

That said, if we look at the block module, the BlockContent entity has a property named "info" which is used for a similar purpose, i.e. to add administrative description. If we want to continue using that pattern, we could add a property named "info. IMHO, the name "info" seems very generic so I'd suggest using something like "admin_description" or even "context" (as we have in string translations).

Answers/opinions/suggestions are welcome (=

sebish’s picture

Status: Needs work » Needs review
StatusFileSize
new74.52 KB

This update takes a shot at implementing the admin_description field for MenuLink entities to give better admin context.

What's been done:
- Added admin_description field to MenuLinkInterface and implementing classes
- Updated MenuTreeStorage schema and field definitions
- Updated User account menu so it uses the new setup (see screenshot attached)
- Fixed a couple performance tests that had hardcoded SQL queries

Current situation:
Got 3 tests failing that seem unrelated to the menu thing:
- 2 settings_tray tests with off-canvas issues
- 1 MySQL installer test about database isolation levels

Not really sure what's up with these - they don't seem connected to the admin_description changes. The menu functionality itself looks like it's working since the performance tests show the new field is getting included in queries properly.

Any thoughts on how to handle these test failures would be helpful!

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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

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.