Problem/Motivation

A node can have links in multiple menus (eg. main menu and footer menu). There is a [node:menu-link] token but it's not possible to specify which link it should return in given situation. It just takes the first one returned by the plugin.manager.menu.link service. This makes it impossible to reliably generate url aliases for nodes based on their position in menu of choice (eg. main menu).

Proposed resolution

Implement [node:menu-link-from-menu:?] dynamic token that will only return links from given menu.

Remaining tasks

  1. Write patch
  2. Review
  3. Write tests

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork token-2850780

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

blazey created an issue. See original summary.

blazey’s picture

Assigned: blazey » Unassigned
Status: Active » Needs review
StatusFileSize
new3.53 KB

Attached patch adds the new [node:menu-link-from-menu:?] token.

It also moves the chained tokens part out of the foreach loop here http://cgit.drupalcode.org/token/tree/token.tokens.inc#n1172. Right now chained tokens are generated as many times as there are tokens. It's redundant because returned values are always the same.

blazey’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 2850780-2.patch, failed testing.

blazey’s picture

Status: Needs work » Needs review
blazey’s picture

Issue summary: View changes
blazey’s picture

Issue summary: View changes
blazey’s picture

Issue summary: View changes
leksat’s picture

StatusFileSize
new3.58 KB

Rerolled on 8.x-1.0.

leksat’s picture

Status: Needs review » Reviewed & tested by the community

Even if we use this patch on a production project for quite some time, I have manually tested the rerolled patch with Token 8.x-1.0 and Drupal 8.3.5. Works as expected!

(Patch #9 provided by me is just a reroll.)

berdir’s picture

Status: Reviewed & tested by the community » Needs work

This looks useful, but it needs tests. Should be as easy as adding some additional tokens to assert below "// Test [node:menu] tokens." in \Drupal\token\Tests\TokenMenuTest::testMenuTokens()

msteurs’s picture

StatusFileSize
new3.6 KB
new3.6 KB

Adding re-roll for Token 8.x-1.3.

msteurs’s picture

stewest’s picture

This seems to be _in_ 8.1.5 ?

shubham.prakash’s picture

Status: Needs work » Needs review
StatusFileSize
new3.62 KB
ngkoutsaik’s picture

Status: Needs review » Needs work

The reroll seems successful and as confirmed above the patch works. However, this still requires tests before it can be marked as RTBC.

sanjayk’s picture

Assigned: Unassigned » sanjayk
sanjayk’s picture

Assigned: sanjayk » Unassigned
Status: Needs work » Needs review

Patch #15 applied successfully. For me RTBC.

pvbergen’s picture

StatusFileSize
new3.62 KB

The patch in #15 is using a deprecated function for Drupal 9 (Node::urlInfo()). I've adapted the patch for Drupal 9.

mighty_webber’s picture

StatusFileSize
new2.26 KB

Patch for drupal 10.6.2 based on #19.

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