Download & Extend

Add [node-menu-parent-alias] token

Project:Token
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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!").

AttachmentSizeStatusTest resultOperations
menu_path_tokens_d5.patch1.73 KBIgnored: Check issue status.NoneNone

Comments

#1

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

#2

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.

#3

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

#4

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!

#5

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.

<?php
/**
* 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;
  }
}
?>

#6

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.

#7

Status:needs work» fixed

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

#8

Status:fixed» closed (fixed)

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

#9

Any chance of a backport to D6?

#10

Version:7.x-1.x-dev» 6.x-1.x-dev
Status:closed (fixed)» needs review

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

AttachmentSizeStatusTest resultOperations
289630-10.patch1.83 KBIdlePASSED: [[SimpleTest]]: [MySQL] 105 pass(es).View details

#11

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

#12

Status:needs review» needs work

#13

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

#14

Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
289630-14.patch1.4 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 289630-14.patch.View details

#15

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

AttachmentSizeStatusTest resultOperations
289630-15.patch1.85 KBIdlePASSED: [[SimpleTest]]: [MySQL] 108 pass(es).View details

#16

Title:Add menupathalias token» Add [node-menu-parent-alias] token

#17

Status:needs review» needs work

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

#18

Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
289630-token-node-menu-parent-path.patch3.54 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 289630-token-node-menu-parent-path.patch.View details

#19

Status:needs review» fixed

Committed #18 to CVS.
http://drupal.org/cvs?commit=463902

#20

Status:fixed» closed (fixed)

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

nobody click here