A variant of [menupath-raw] which excludes the current node, or a token which provides [title-raw] when [menupath-raw] is empty
| Project: | Token |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
I would like to use the [menupath-raw] in the pathauto module like [menupath-raw]/[title-raw] but [menupath-raw] contains the current node's menu title so there will be duplicated information in the url about current node: menuparent1/menuparent2/currentnodemenuitemtitle/currentnodetitle
I woult like to get in the url (after menu parent titles) one of the node's title or node's menu title.
e.g:
menuparent1/menuparent2/currentnodetitle
or
menuparent1/menuparent2/currentnodemenuitemtitle
I can't use only [menupath-raw] because nodes which doesn't have menu entry will not have path because [menupath-raw] returns nothing.
How can I create a token like [menupath-raw] without the last (current) item?
Or.. Any other solution welcomed.

#1
subscribing... would love to get help with this as well!!
#2
Subscribing
#3
+1 for either some kind of [titleless-menupath-raw] token (so that we can use [titleless-menupath-raw][title-raw] -- the absence of a slash between the tokens is important for when there is no menu item), or else something like the following (which I have as a separate pathauto_titletoken.module, but would be much better if integrated into token_node.inc)
It might even be nice to have both tokens, because the title used when [menupath-raw] is populated could be different to the [title-raw] title.
<?php
/**
* @file
* Provides [title-or-menupath-raw] token for pathauto titles.
*/
/**
* Implementation of hook_token_list().
*/
function pathauto_titletoken_token_list($type = 'all') {
if ($type == 'node' || $type == 'all') {
$tokens['node']['title-or-menupath-raw'] = t("A path-auto token returning [menupath-raw] if applicable, and [title-raw] if not.");
return $tokens;
}
}
/**
* Implementation of hook_token_values().
*
* Replacement for ['title-or-menupath-raw'], for use with pathauto.
* The 'path-raw' suffix is important: @see pathauto_clean_token_values().
* Otherwise the '/'s are stripped from the alias.
*
* Code is adapted from node_token_values() in token_node.inc
*/
function pathauto_titletoken_token_values($type, $object = NULL) {
$values = array();
if ($type == 'node') {
$node = $object;
if (!empty($node->menu['mlid'])) {
if ($menu_link = menu_link_load($node->menu['mlid'])) {
$trail_raw = _menu_titles($menu_link, $node->nid);
$menupath_raw = implode('/', $trail_raw);
}
}
$values['title-or-menupath-raw'] = !empty($menupath_raw) ? $menupath_raw : $node->title;
}
return $values;
}
?>
#4
Subscribing, so I can link people with the same question to this issue. I also wrote a custom module to achieve the same thing, but jweowu's code in #3 is much more elegant. :)
#5
Here's a patch for token_node.inc to integrate [title-or-menupath] and [title-or-menupath-raw] (which is completely trivial, done this way).
peterjmag: Was there a particular reason you reverted the issue title and category? It's definitely a feature request, and the other title seemed rather more descriptive.
#6
#7
jweowu: My apologies, I don't know how that happened!
#8
Cross-linking to #640136: [menupath] / [menupath-raw] omits menu link title of new node in some circumstances in case it helps anyone.
There's an updated version of the module code from #3 in that issue.