4

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.

1
  • Is this Drupal 6?
    – donquixote
    Nov 9, 2013 at 2:37

2 Answers 2

1

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)

2
  • 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, 2011 at 16:49
  • CER would help populate behind the scenes, really another question all together but if you did the refs both ways you wouldn't have to keep up with those, CER would sync them for you. Project page: drupal.org/project/cer (of course there are other ways but CER IMHO the best choice for situations like this) Jan 23, 2015 at 6:43
0

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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