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:

  1. Department Administration: Introduction and Overview
  2. Human Resources
  3. 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!").

Comments

xjm’s picture

* 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.

greggles’s picture

Title: Add "real" menu path handling » Add menupathalias token
Version: 5.x-1.9 » 6.x-1.x-dev
Status: Needs review » Needs work

Thanks 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.

gg4’s picture

So, is this going to be added to 6.x?

xjm’s picture

When 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!

gg4’s picture

Here 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.


/**
* Implementation of hook_token_values().
*
*/
function token_parent_path_alias_token_values($type, $object = NULL) {
  $values = array();
  if ($type == 'node') {
    $node = $object;

	if (!empty($node->menu['plid'])) { // Make sure menu item has a parent
        
		$parent_mlid = $node->menu['plid']; // Get the mlid of the parent
			
		$parent_object = menu_node_get_node($parent_mlid);  // Return a node object for the closest parent
	
		$parent_path = $parent_object->path; // Pull the path out of the parent node object
	
		$values['parent_path_alias'] = $parent_path; // Set token
    
		if ($parent_path == 'node/'.$parent_object->nid) { // If there is not an alias, return nothing
			$values['parent_path_alias'] = '';
		}
    }

    else {
    	$values['parent_path_alias'] = '';
   	}

  	return $values;
	}
}

/**
* Implementation of hook_token_list().
*/
function token_parent_path_alias_token_list($type = 'all') {
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['parent_path_alias'] = t("The path alias of the closest parent menu item. CAUTION - Be careful with bulk-updating content using this token."); 
    return $tokens;
  }
}

dave reid’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

I think we just need [node:menu] and [node:menu:parent:url] in D7 where this is much better possible.

dave reid’s picture

Status: Needs work » Fixed

This is now available in token.module for D7 as [node:menu-link:parent:url]

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

xjm’s picture

Any chance of a backport to D6?

xjm’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new1.83 KB

Here's a 6.x version of this feature.

dave reid’s picture

The token name is not evident that this is using the parent. I would suggest [node-menu-parent-alias].

dave reid’s picture

Status: Needs review » Needs work
xjm’s picture

I just used greggles' suggestion. I'll rename it as you suggest and reroll.

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.4 KB
xjm’s picture

StatusFileSize
new1.85 KB

Doh. Rolled against the patched version rather than the current -dev. Re-queuing with a correct patch.

xjm’s picture

Title: Add menupathalias token » Add [node-menu-parent-alias] token
dave reid’s picture

Status: Needs review » Needs work

Will need to be re-rolled for changes to menu link token handling.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new3.54 KB
dave reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.