Node-comment target as token

opensanta - June 3, 2009 - 23:42
Project:Node comments
Version:6.x-2.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Is it possible to load the node on which a nodecomment was made with token?

#1

opensanta - June 3, 2009 - 23:45

Or, is it possible to save the node-comment target as a node reference?

#2

webchick - June 6, 2009 - 02:30
Version:6.x-1.x-dev» 6.x-2.x-dev

I'd like this too.

#3

merlinofchaos - August 10, 2009 - 23:05

Token isn't very good at having multiple nodes. Maybe with token 2.x

#4

vood002 - September 4, 2009 - 00:30

Would love to see this.

I built a discussion rss feed which aggregates all of the node comments (and forum topics) on my site--only problem is if you click through the link it takes you to the comment node, rather than it's parent node.

If the parent NID were a token, I'm assuming I could use pathauto to this effect: node/[pid]#reply-[nid]

EDIT now that i think about it the pathauto way definitely won't work. I may be able to achieve it with views, i'll post if I find a good way.

If there's another way to do this I'd appreciate advice as well.

#5

friolator - September 23, 2009 - 22:27

@vood002:

We have a custom breadcrumb trail for certain sections of our site, that's based on the current path. We're still using paths that contain named anchors, for the nodecomment view of all the comments attached to a node. This is there so you can make a link to that comment in the context of the overall thread. The big problem for us was in search results for the site. Nodecomment nodes would be linked to via their node id (node/nid), but we needed for the path to show the context of the comment, in order to work inside of our breadcrumb trail. This is especially important with search results, where you'd be taken to the nodecomment as a standalone post. The breadcrumb becomes critical for letting you know where you are.

Our breadcrumbs would come out all weird if the path generated by pathauto was 'forum/comment-title' vs 'forum/container/forum/node-title/comment-title' -- in the case of the latter, we can construct a breadcrumb that lets the user navigate back up easily. Also, we needed that for the case where (in search results), you're linked directly to the node.

Ok, that said, I did this:

<?php
function cd_misc_token_values($type, $object = NULL) {
 
$values = array();
  switch (
$type) {
    case
'node':
      if (
$object->type == "forum_reply"){
       
//determine the nodecomment's parent's path, pass it along to Token.
       
$values['node-comment-parent-path'] = drupal_lookup_path('alias', 'node/'.$object->comment_target_nid);
      }
      break;   
  }
  return
$values;
}

function
cd_misc_token_list($type = 'all') {
  if (
$type == 'node' || $type == 'all') {
   
$tokens['node']['node-comment-parent-path']    = t('The path to the parent of this node comment.');
    return
$tokens;
  }
}
?>

So, this gives us a [node-comment-parent-path] token for use in pathauto. What we've done is set up the following paths:

Forum Topic: forum/[termpath-raw]/[title-raw] (gives us 'forum/container/forum/node-title')
Forum Reply: [node-comment-parent-path]/[title-raw] (gives us 'forum/container/forum/node-title/comment-title')

So far, this seems to work fine. I suppose this could be patched into nodecomment itself if people find it useful enough. The only catch I can see is that "forum_reply" is specific to our site. I guess it should just check for the existence of $object->comment_target_nid, and if it's there, go ahead and make this token. (unless there's a better way)

 
 

Drupal is a registered trademark of Dries Buytaert.