The existing menupath token doesn't actually use the path aliases of menu trail nodes. Instead, it generates a fake "path" out of the titles of items in the menu trail.
Example: Suppose you have three nodes in the following menu structure [nids in brackets]:
Administration [1]
-- Human Resources [2]
----Employment [3]
These nodes have the following node titles:
- Department Administration: Introduction and Overview
- Human Resources
- Become one of the team!
The URL alias for [1] is dept; the alias for [2] is dept/hr. Suppose we use the existing [menupath] token with the pathauto module to automatically generate a URL alias for [3]. The generated URL alias would be something like:
department-administration-introduction-overview/human-resources/become-one-team
This doesn't at all create the sense of [3] being an item "inside" the admin/hr "directory". A much better alias would be:
dept/hr/employment
which would reflect both the information in the menu and the implied "directory" hierarchy.
I added two tokens to my copy of the token module to address this: [parent_path_alias], which is the URL alias, if any, of the node's immediate parent in the menu system; and menu_title, which is based on the title of the node's entry in the menu system (e.g., "Employment") rather than the title of the node itself ("Become one of the team!").
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 289630-token-node-menu-parent-path.patch | 3.54 KB | dave reid |
| #15 | 289630-15.patch | 1.85 KB | xjm |
| #14 | 289630-14.patch | 1.4 KB | xjm |
| #10 | 289630-10.patch | 1.83 KB | xjm |
| menu_path_tokens_d5.patch | 1.73 KB | xjm |
Comments
Comment #1
xjm* That should have been "
dept/hr'directory' " above, but I think it's still fairly clear.For clarification, I have pathauto set to generate node aliases with this token pattern to achieve the desired aliasing:
[parent_path_alias]/[menu_title].The application in conjunction with pathauto was the most important one to me, but I can see these tokens being used in a variety of situations.
Comment #2
gregglesThanks for the idea and patch, xjm. I think this is a reasonable token to provide but there are a few corrections before it can be committed.
First, the "ADDED BY" and "END ADDITION" pieces should be removed.
Also, this is a fairly common thing to provide, but is generally called "*alias" (see term and termalias or bookpath and bookpathalias). I think this should be called "menupathalias".
Finally, if possible I'd prefer to add this feature to 6.x first or at least have patches for both 5.x and 6.x
Thanks again.
Comment #3
gg4 commentedSo, is this going to be added to 6.x?
Comment #4
xjmWhen I submitted the issue last year none of my sites were in D6 so I didn't really have an incentive to do anything beyond just submit the idea for anyone else interested. :) I'm in the process of migrating to 6.x now and will probably be patching my 6.x token.module when I get there in a couple weeks; if so I'll upload a (clean) patch to this issue when I do. Of course, feel free to make your own patch if you like!
Comment #5
gg4 commentedHere is a quick attempt at providing a ['parent_path_alias'] token. This requires the Menu Node API module, which is very useful. Since it depends on a module that token does not, I though it best not to post it in patch form.
Comment #6
dave reidI think we just need [node:menu] and [node:menu:parent:url] in D7 where this is much better possible.
Comment #7
dave reidThis is now available in token.module for D7 as [node:menu-link:parent:url]
Comment #9
xjmAny chance of a backport to D6?
Comment #10
xjmHere's a 6.x version of this feature.
Comment #11
dave reidThe token name is not evident that this is using the parent. I would suggest [node-menu-parent-alias].
Comment #12
dave reidComment #13
xjmI just used greggles' suggestion. I'll rename it as you suggest and reroll.
Comment #14
xjmComment #15
xjmDoh. Rolled against the patched version rather than the current -dev. Re-queuing with a correct patch.
Comment #16
xjmComment #17
dave reidWill need to be re-rolled for changes to menu link token handling.
Comment #18
dave reidComment #19
dave reidCommitted #18 to CVS.
http://drupal.org/cvs?commit=463902