Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm having trouble getting my URL Aliases to cooperate with certain Tokens... specifically Tokens generated by the CCK Node Reference module. Here is the URL structure that I'm trying to establish:

/department/course/lecture

Each section refers to a referenced node... so a lecture refers to a course which refers to a department. Make sense? My URL Alias structure, with Tokens in place, looks like this:

[field_course_department-title-raw]/[field_course_number-raw]/[field_lecture_display_number-raw]

When the URL Alias gets generated, it becomes:

/%5Bfield_course_department-title-raw%5D/%5Bfield_course_number-raw%5D/lecture-2

So the only Token that is working is the lecture (the last one). The first two tokens aren't even recognized by Drupal and, as you can see, are encoding the brackets from the Tokens into HTML entity codes. Those two are also the CCK Node Reference fields. Worth mentioning, the two offending Tokens were present and available in the Replacement Patterns section on the URL Alias settings page... so it would seem that Drupal should be able to recognize them, right?

What's going on here?! Help! Any ideas or suggestions would be greatly appreciated! Thanks in advance.

share|improve this question
    
Is this Drupal 6? –  donquixote Nov 9 '13 at 2:37
add comment

2 Answers

The issue I_THINK is that tokens are only generated on content in the current node, eg, it has no inherent intelligence to walk up the hierarchy of node references to find all your other info stored in other nodes.

So, it would appear you have a node ref to the course already in your lecture, so just make sure you have the correct [TOKEN] there (TOKEN-title-raw instead of TOKEN-number-raw perhaps?) but to get up level to the department, you probably have to put a field in your lecture node and populate it behind the scenes with the department node reference (via hook_nodeapi() and $op presave by node_load()ing the nid of the course and getting it from there)

share|improve this answer
    
Okay... that sounds logical. Thanks! Can you elaborate on how I might populate it behind the scenes with the department node reference? Is there a module that might help me out or is this more of a custom code type thing? –  Sam Nov 29 '11 at 16:49
add comment

You would use nodeapi() something like this:

YOURMODULE_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  if ($node->type=='lecture' && $op == 'presave') {
    // grab the nid of the course and load it...
    $course=node_load($node->field_course[0]['nid']);  
    // set the nid of the course's department in a field in the lecture...
    $node->field_department[0]['nid']=$course->field_department[0]['nid'];  
  }

}

Of course, you'll have to have added the department field to your lecture node type, plus set all the field_XXXX to your exact system's as well.

To do this without your users seeing it, you can use the Node Form Columns module to hide the field if its not required (http://drupal.org/project/nodeformcols) or don't let them edit the field with permissions which should hide it or if none of that works, just display:none it with css :)

Disclaimer: I just typed all this in from memory so there may be typos but the gist is here I hope :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.