Project:Menu Trails
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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

Comments

#1

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

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.

#3

Thank you so much for posting this patch!

I registered on drupal.org a moment ago just to say this. I spent a very frustrating day trying all sorts of ways to syncronise menu trails with nodereference, url ailias, or anything that doesn't come out of the box with drupal or Menu Trails. This morning I bit the bullet and applied the patch manually to the latest dev release and it worked straight away.

This patch just has to go into the next release. Similar functionality would also be very desirable for the taxonomy term section, so that the site's editors wouldn't have to go into the module's settings screen every time they create a new term.

Haven't tested the breadcrumb synch yet - the original version didn't work too well for taxonomy, so I had to roll a path alias script based on some other solutions. If this works I may be able to comment-out my own.

Thanks again,
Karina

#4

Status:active» needs work

There's a patch but it apparently needs work as suggested in comment #1.

#5

updated the patch with code from comment #1 and 6.x-1.x-dev (date 2010-Jan-09)

AttachmentSize
menutrails.module.patch 2.64 KB

#6

Status:needs work» needs review

#7

I've just tested the patch from comment #5. It partially works:

The node reference menutrail is perfect

Instead, if you set a menu trail for some content types and for one node reference field, the settings for the content type are not applied. For example I've the content type "teacher" with a menu trail, I've another content type with a node reference field with the node reference menu trail. The menu trails works only for the content type with a node reference, but the other setting not.

I think the patch should allow to have multiple configurations. What do you think?

#8

I suggest to add a simple check in the code block added in menutrails_node_location():

  if (module_exists('nodereference') && empty($href) ) {

In this way you can apply a menu trails for node reference fields and for node types together (I don't know what it could happen if the node type configured in the node type settings also have a node reference field... fortunatly it is not my case :-) :-) :-) :-) )

AttachmentSize
menutrails.module_2.patch 2.65 KB

#9

Thanks for the patch guys, it works just fine!

One thing I fixed is that if you have several node reference fields on the node, and you want only one to be considered for the trail, you can't do that since there is no checking against Menu Trail settings.

I've added a bit of comparison and it works as expected now.

foreach ($node_ref_trails as $key => $value) {
+      if (isset($node->$key) && $value == 1) {
...

&& $value == 1 checks if you have selected this particular field for consideration.

AttachmentSize
menutrails.503024.9.patch 2.67 KB

#10

great addition!

#11

I just tried this out and it works like a charm, would love to see this commited!

#12

What about the status of this patch? And what about the question regarding a multiple configuration (see my #8 comment) ?

#13

We are currently using this for several sites now, it's excellent for node reference built hierarchies of content. I would love to test more if needed and would be glad to see this commited soon!

#14

I tried the latest patch (#9) against the 1.1 branch of Menu Trails - I assume there is not much difference between the 1.x-dev and 1.1 branch given they were released a day apart.

The patch applied successfully but the functionality doesn't seem to be there. Can someone provide a few instructions on how to use this?

I have a content type for City and a content type for Country. I set my Parent Item for City under "Node Types" to None. (Previously the Parent Item had been "Country".) Then under the second "Node Types" fieldset, I checked "field_city" and "field_country".

My city, "Paris", has a reference to "France". When I view "Paris" I would expect the trail to be something like "Home > France > Paris". Instead it is "Home > Country > Paris".

I have cleared the caches. Any ideas?

#15

#14, your setup should work. I did the exact same thing for a couple of sites now that uses Product as a reference to Page. The only trail i configure is the node reference field and i get pretty trails using a subnavigation provided by Menu block. I do haven't paid much attention to breadcrumbs though, only that my menu items get a nice active-trail class (which they do). I think there is a breadcrumb setting in Menu trails, try switching it on/off.

#16

subscribe

#17

I was just searching for some functionality like this! This would be a great addition, thanks for the work on it!

#18

The patch works fine, thanks !
I just modified the title "Node types" which may be confusing and put "Node references" instead.

AttachmentSize
menutrails.503024.17.patch 2.67 KB

#19

Should the parent node be referring to the child node or the other way around?

Currently, I have a landing page with child page teasers 'embedded' onto it using node references and I don't get a breadcrumb that shows their relationship.

nobody click here