Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
There is a token returning names of all parents of a menu link. In some situations (eg. pathauto + easy_breadcrumb) it is required to get paths of parent menu items and there is no such token.
Proposed resolution
Add [menu-link:parents-paths] token and write tests.
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#6 | 2847694-6.patch | 9.29 KB | blazey |
#2 | 2847694-2-test-only.patch | 4.47 KB | blazey |
Comments
Comment #2
blazey CreditAttribution: blazey at Amazee Labs commentedAttaching patch and a test.
Comment #3
blazey CreditAttribution: blazey at Amazee Labs commentedComment #6
blazey CreditAttribution: blazey at Amazee Labs commentedAttaching combined patch.
Comment #7
Leksat CreditAttribution: Leksat at Amazee Labs commented@blazey,
I tested your patch with simplytest.
1. Somehow, the new token did not work for me.
I set pathauto pattern for content like "[node:menu-link:parents-paths]/[node:title]" and created 3 nodes with menu links one under another. Here is the result: https://www.drupal.org/files/issues/2850780-2-test.png
But if it worked, I guess, it would produce something like this:
- /test-1
-- /test-1/test-2
--- /test-1/test-1/test-2/test-3
Correct?
If yes - this does not really make sense.
2. I tried to use "[node:menu-link:parent:url:path]/[node:title]" pattern instead.
The result looks like something SEO friendly: https://www.drupal.org/files/issues/2850780-node--menu-link--parent--url...
Maybe this is what you tried to achieve?
Comment #8
blazey CreditAttribution: blazey at Amazee Labs commented@leksat
[node:menu-link:parents-paths]
is an array type token so separator is needed in order to use it as a string.[node:menu-link:parents-paths:join:/]
would work in this scenario.I agree navigation can be done this way. In fact, I ended up using
[node:menu-link-from-menu:main:parent:url:path]
from #2850780: Can't reference node's menu link from a specific menu. Maybe at some point someone will need combined paths too :)Comment #9
BerdirThanks, started reviewing the test but the last point might make the others irrelevant.
wrong comment.
Should be possible to use \Drupal\simpletest\NodeCreationTrait for this..
why would there be menu links in a menu that we just created?
Actually, wondering if we can't integrate this into \Drupal\token\Tests\TokenMenuTest, that already creates menu links, so we just need to add the additional tokens?