adding node reference support

BenKewell - June 26, 2009 - 13:50
Project:Menu Trails
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

attached patch add support to node reference fields
the node reference field in a node can be used to declare menu trail

i need such feature in a new website
so maybe someone else want this feature too

AttachmentSize
menutrails.module.patch2.3 KB

#1

brian_c - August 21, 2009 - 08:31

Fantastic addition, thanks. Allowing menutrail parents to be setup like this on a per-node basis adds tremendous flexibility, no more need to have a different content-type or taxonomy term for every possible parent.

I found a limitation to your patch; if the referenced node ITSELF has a menu path defined by menutrails (ie, it doesn't exist in menu_links table) then this won't work. I got it working by adding the following code in menutrails_node_location(), after your new line $href = 'node/'. $node_reference[0]['nid'];:

<?php
   
// check if this path exists in menu_links
   
if (db_result(db_query("SELECT count(mlid) FROM {menu_links} WHERE link_path = '%s'", $href)) == 0) {
       
// it doesn't exist, we need to keep going, call self recursively
       
return menutrails_node_location( node_load( $node_reference[0]['nid'] ) );
    }
?>

One thing to note, menutrails_node_location() does a quick test at the beginning to see if menu_get_item() is present in menu_links, and quickly return if it is. This test only needs to be done ONCE, however it will be done multiple times if this recursive call I've added is used. I plan on re-factoring this later to eliminate this redundancy.

#2

smithmb - August 24, 2009 - 18:11

This is a great feature. I can't wait to see this get into the dev release, and I'm sure I'm not the only one who could use the flexibility.

 
 

Drupal is a registered trademark of Dries Buytaert.