Account for nodecomment anchor link inconsistancy

Michelle - November 9, 2009 - 17:01
Project:Node comments
Version:6.x-2.x-dev
Component:Comment module inconsistencies
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I'm tentatively labeling this as a bug. It's probably by design but has an (I'm assuming) unintended side effect. The comment module puts in <a id="comment-12345"> for an anchor link. This is used when you submit a comment to take you back to that comment. It's also used for jump links in Advanced Forum. Possibly other places as well.

If you use the default "comment" node type, there is no problem. However, if you change this, as I did, to, for example, "forum-reply" you then end up with <a id="forum-reply-12345"> which breaks all those links. Having the node type there is more accurate as far as markup making sense but I think it would be better to just leave that as "comment" no matter what the node type for consistency in linking.

Michelle

#1

Michelle - November 9, 2009 - 18:17
Title:Using a node type other than "comment" breaks anchor links» Nodecomment does not add comment-### anchor links.

On further investigation, it seems I was wrong about the exact nature of the problem. Because I forgot Advanced Forum adds <a id="forum-reply-12345">, I was thinking that was added by nodecomment because, by sheer coincidence, my nodecomment node type is forum-reply.

What is actually happening is that nodecomment isn't adding that anchor link at all. I took AF out of the equation by making two non-forum node types, one with nodecomment and one without, and compared. The one without nodecomment gets the anchor link and the one with nodecomment does not.

The relevant comment.module code is this:

<?php
function theme_comment_view($comment, $node, $links = array(), $visible = TRUE) {
  static
$first_new = TRUE;

 
$output = '';
 
$comment->new = node_mark($comment->nid, $comment->timestamp);
  if (
$first_new && $comment->new != MARK_READ) {
   
// Assign the anchor only for the first new comment. This avoids duplicate
    // id attributes on a page.
   
$first_new = FALSE;
   
$output .= "<a id=\"new\"></a>\n";
  }

 
$output .= "<a id=\"comment-$comment->cid\"></a>\n";

 
// Switch to folded/unfolded view of the comment
 
if ($visible) {
   
$comment->comment = check_markup($comment->comment, $comment->format, FALSE);

   
// Comment API hook
   
comment_invoke_comment($comment, 'view');

   
$output .= theme('comment', $comment, $node, $links);
  }
  else {
   
$output .= theme('comment_folded', $comment);
  }

  return
$output;
}
?>

As far as I can tell, both from looking at the output and looking at the code of nodecomment, there is no equivalent of $output .= "<a id=\"comment-$comment->cid\"></a>\n"; in there, which is what's needed.

I don't know where the best place to put it would be. node-comment.tpl.php seems like the most logical place for something like that but, unfortunately, that makes it inconsistent with the comment module because the comment module adds it outside the template. This means that any alternate templates that are used would have to check if it's comment or nodecomment in use to know whether to add it or not. That's not impossible to do, but I'm hoping someone has a better suggestion that I'm not thinking of. :)

Thanks,

Michelle

#2

Michelle - November 9, 2009 - 19:54
Title:Nodecomment does not add comment-### anchor links.» Interfers with nodecomment template on non AF nodes
Project:Node comments» Advanced Forum
Version:6.x-2.x-dev» 6.x-2.x-dev
Component:Comment module inconsistencies» Other module integration

Ok, I dug into this even more and it does appear to have something to do with AF though, at this point, I haven't the foggiest idea how. As I said in the previous post, I could reproduce this problem on node types that were not styled with AF. The problem turned out to be that it was using the default node.tpl.php in Garland rather than node-comment.tpl.php from nodecomment. On the surface, it didn't seem like it had anything to do with AF. However, completely removing AF from the site does fix the problem. My best guess is there's something in the code that checks to see if AF should style it that is some how interfering. Will need to dig into it more.

Michelle

#3

Michelle - November 9, 2009 - 20:29
Title:Interfers with nodecomment template on non AF nodes» Account for nodecomment anchor link inconsistancy
Category:bug report» task

Or maybe not. This is one confusing issue. I re-enabled AF and it's still working fine on the non AF nodes so I guess it wasn't AF causing the problem after all. Whatever the problem was must have been fixed by submitting the modules page, I guess.

At any rate, this whole thing has pointed out that AF needs to deal with the fact that nodecomment and comment do the anchor link differently. Because NC is relying on you to use their template to make it work, I'll have to add extra code to AF to make it work with NC as well as C.

If anyone else runs into this trouble of nodecomment using node.tpl.php while AF is enabled, let me know. Since I don't know what caused that weirdness, there's always a chance that it was AF, after all. Since I can no longer reproduce it, I'm not going to chase it anymore.

Michelle

#4

Michelle - November 9, 2009 - 21:25
Status:active» fixed

Ok, been a crazy issue but I've got it fixed from AF's perspective. I put code in to tell if it's a nodecomment node and add the missing anchor in that case. It's not an ideal solution since it means there's still an inconsistency between nodecomment and comment but, from talking on IRC, that doesn't seem to be a concern.

Michelle

#5

merlinofchaos - November 9, 2009 - 21:50
Category:task» bug report
Status:fixed» active

from talking on IRC, that doesn't seem to be a concern.

You can get mad and storm out of IRC if you want, but there's no reason to be mean to me in the issue queue.

#6

merlinofchaos - November 9, 2009 - 22:06
Project:Advanced Forum» Node comments
Version:6.x-2.x-dev» 6.x-2.x-dev
Component:Other module integration» Comment module inconsistencies

For the record, I said nothing of the sort on IRC. Moving back to node comment so I can actually understand the issue rather than having words put in my mouth.

#7

Michelle - November 10, 2009 - 02:34

I think we're talking past each other. I'm neither mad at you nor trying to be mean to you. I left your channel because I thought I was bothering you. As for this issue, I guess I misunderstood. I thought you were ok with the in template solution so I just changed AF to work around it.

Sorry if I upset you. It wasn't intentional. :(

Michelle

 
 

Drupal is a registered trademark of Dries Buytaert.