One node belongs to multiple menus, need a way to specify menu when generating

Created on 13 March 2018, about 7 years ago
Updated 13 December 2023, over 1 year ago

I am generating URL aliases for content based off of this pattern: [node:menu-link:parents:join-path]/[node:title]

Most of my content belongs to more than one menu, the main menu, and various sub-menus which appear in various pages in the sidebar.

The sidebar menus were created recently and upon their creation generating aliases for content is based off of those submenus, which I don't want. I want their aliases to be generated based off of the main menu.

I've looked all over and can't find a solution to specify which menu I want the aliases to be generated from, but maybe I haven't look hard enough. If that is the case, please guide me in the right direction and close this issue.

Thanks

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States georgeshaw

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    I think this belongs in Token's issue queue.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    You can always implement your own tokens that limit to the menu you want, along the lines of _menu_ui_tokens(), this might be complex to do in a generic way.

    That said, _token_menu_link_best_match() already at tempts to find the link that is used on the node edit form. If you only allow the main menu there, that should just work.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Yeah, I was just investigating this too. If a node is part of multiple menus, Token will use the menu link that was part of the node form submission when resolving the token. Of course nodes can be saved outside of a form submission. In this case, it will defer to Menu UI's menu_ui_get_menu_link_defaults method to find the menu link to use. This is the same logic that Menu UI uses on the node form when selecting the menu link to show on the node form.

    So I think the solution here for nodes: edit the node type form and set the default menu to the one that you prefer to be used for token generation. I think the majority of the time whatever you have set as the default menu for the node type will match what you want pathauto/token to use.

  • πŸ‡¨πŸ‡­Switzerland stefanos.petrakis@gmail.com Biel, Switzerland

    stefanos.petrakis β†’ made their first commit to this issue’s fork.

  • Pipeline finished with Failed
    3 days ago
    Total: 595s
    #500044
  • πŸ‡¨πŸ‡­Switzerland stefanos.petrakis@gmail.com Biel, Switzerland

    Here is an naive idea using events.
    The reasons behind it:

    (a) Using the default menu and relying on the node edit form, works by extending the complexity of the node edit form, which may not be ideal in some cases. And also, this approach does not work when going via Pathauto (and any other programmatic use of related tokens).
    (a) Implementing custom tokens would work, but then, one would be missing (and probably copy-pasting) all the goodness that comes with the current implementation of token_tokens()

    Putting this out there as it does help us solve our version of the same problem.

Production build 0.71.5 2024