Add MenuLinkInterface::getAdminLabel()

Created on 15 September 2015, over 9 years ago
Updated 30 September 2024, 5 months ago

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.

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Menu systemย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nikhil_110

    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
  • last update almost 2 years ago
    29,361 pass
  • First commit to issue fork.
  • First commit to issue fork.
  • @mrinalini9 opened merge request.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mrinalini9 New Delhi

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

    Thanks!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    @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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada sebish

    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.

    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.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada jigarius Montrรฉal

    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 (=

Production build 0.71.5 2024