A variant of [menupath-raw] which excludes the current node, or a token which provides [title-raw] when [menupath-raw] is empty

kepesv - July 15, 2009 - 10:52
Project:Token
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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

alisonjo2786 - July 27, 2009 - 23:53

subscribing... would love to get help with this as well!!

#2

svihel - August 27, 2009 - 14:48

Subscribing

#3

jweowu - October 22, 2009 - 05:32
Title:[menupath-raw] without current node » A variant of [menupath-raw] which excludes the current node, or a token which provides [title-raw] when [menupath-raw] is empty
Category:support request» feature request

+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

peterjmag - October 26, 2009 - 17:37
Title:A variant of [menupath-raw] which excludes the current node, or a token which provides [title-raw] when [menupath-raw] is empty» [menupath-raw] without current node
Category:feature request» support request

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

jweowu - October 26, 2009 - 23:40

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.

AttachmentSize
token-519834-5.patch 4.12 KB

#6

jweowu - October 26, 2009 - 23:42
Category:support request» feature request
Status:active» needs review

#7

peterjmag - October 29, 2009 - 07:08
Title:[menupath-raw] without current node » A variant of [menupath-raw] which excludes the current node, or a token which provides [title-raw] when [menupath-raw] is empty

jweowu: My apologies, I don't know how that happened!

#8

jweowu - November 23, 2009 - 02:47

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.

 
 

Drupal is a registered trademark of Dries Buytaert.