Alter comment links.

neochief - February 14, 2009 - 18:23
Project:Drupal
Version:6.x-dev
Component:comment.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Currently, it's not possible to alter comment links from your own module.

Their links are not pasing through the drupal_alter. I've made a patches wich are fixing this. Please, take a look.

AttachmentSizeStatusTest resultOperations
comments_link_alter_D6.patch1.09 KBIgnoredNoneNone
comments_link_alter_D7.patch1.07 KBIdleFailed: Failed to apply patch.View details | Re-test

#1

mr.baileys - February 23, 2009 - 07:45
Status:active» won't fix

Hmmm, I'm fairly certain that comment.module already has this. See for example this snippet (from D7, around line #1070):

<?php
if ($comment = $result->fetchObject()) {
 
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
 
$links = module_invoke_all('link', 'comment', $comment, 1);
 
drupal_alter('link', $links, $node);

 
$output .= theme('comment_view', $comment, $node, $links);
}
?>

(Also, I think calls like drupal_alter and module_invoke_all probably shouldn't be called from the theme layer, as themeing should only be concerned with presentation.)

If you still think this is a bug, please open a support request and describe in detail:

  1. What code you are using in your module to alter the links
  2. What you expect the result to be
  3. Steps on how we can reproduce this

#2

neochief - February 23, 2009 - 12:22
Status:won't fix» active

Thanks for reply, mr.baileys. Your code affects only single-coment view (for example, when you replying to comment). But if you'll see little lower in the code (line #1132) in place where rendering comment threads, you'll see that this alter is not triggerring at all. I agree that altering in theme layer is not a best way. But invoking the hooks as well (#1830, #1865). Maybe we should place these hooks into comment_render and do averything there. If so, give me a shot and I'll prepare the patch.

I need these alters for my module ajax_comments. Currently I have an ability to override comment links only in preprocess function. And it would be enough for me, if preprocess functions called for theme functions as well. But they not. And if theme don't have a comment.tpl.php, I have no way to alter comment links at all.

#3

mr.baileys - February 23, 2009 - 13:28
Category:bug report» feature request

Thanks for the clarification. I do think this is a feature request though, as nothing is currently broken (marking as such). Can you supply a new patch for review?

#4

neochief - February 23, 2009 - 14:08
Status:active» needs review

Here it is.

AttachmentSizeStatusTest resultOperations
comment_alter_links.patch2.66 KBIdleFailed: Failed to apply patch.View details | Re-test

#5

System Message - February 23, 2009 - 14:20
Status:needs review» needs work

The last submitted patch failed testing.

#6

neochief - February 23, 2009 - 15:08
AttachmentSizeStatusTest resultOperations
comment_alter_links.patch2.71 KBIdleFailed: Invalid PHP syntax in modules/comment/comment.module .View details | Re-test

#7

neochief - February 23, 2009 - 15:09
Status:needs work» needs review

#8

System Message - February 24, 2009 - 17:00
Status:needs review» needs work

The last submitted patch failed testing.

#9

neochief - February 24, 2009 - 17:51

Huh? Invalid PHP syntax? What is it? Patch is straight forward.

#10

mr.baileys - February 24, 2009 - 20:06

Not sure, I've applied the patch locally without issues. You can request a re-test.

#11

neochief - February 24, 2009 - 21:26

I think it's because of #332967: Detect non-unix newlines . Here's a patch with LF only.

AttachmentSizeStatusTest resultOperations
comment_alter_links1.patch2.64 KBIdlePassed: 10931 passes, 0 fails, 0 exceptionsView details | Re-test

#12

neochief - February 24, 2009 - 21:27
Status:needs work» needs review

#13

neochief - April 18, 2009 - 10:49

Bumping this up, as all test passed successfully.

#14

moshe weitzman - April 25, 2009 - 03:48

One approach that would be more work but much more useful would be to make comment thread use drupal_render() style array. then hook_page_alter() could fiddle with comment links. That need not stop this patch though.

#15

catch - April 27, 2009 - 00:25
Status:needs review» needs work

http://api.drupal.org/api/function/hook_link_alter/7 needs updating even if this is only an interim patch.

#16

neochief - April 27, 2009 - 10:59

@moshe weitzman, yes, I agree and I can handle it. But maybe it should be done in a new issue, and this one just commited as-is?

@catch, sorry, I don't understand what update do you mean. The hook_link_alter's concept wasn't changed by my patch at all, I just added it to missing places.

#17

catch - April 27, 2009 - 13:15

neochief - the phpdoc for hook_link_alter() is completely wrong. This is more the fault of the node rendering patch than this one, but we should at least state explicitly that it works for comments now. Probably the parameter should be $comment instead of $node as well.

#18

voxpelli - September 10, 2009 - 11:29
Category:feature request» bug report

This really needs to be fixed in Drupal 6 (and probably 7) because as it is now hook_link_alter() is run inconsistently on comments which isn't very good at all and should be considered a bug. It would have been a feature request only if hook_link_alter() was never run on comments.

Anyone having a plan on how we can solve this issue? Since we're in code freeze for D7 any plans on doing new cool solutions to solve this problem is no longer feasible, so the simple fix that the current patch contains should be applied on both D7 and D6 - since it's a bug fix and shouldn't be affected by any code freeze.

#19

catch - September 10, 2009 - 13:48
Version:7.x-dev» 6.x-dev

comment links can now be alter in hook_comment_build_alter(), so moving this back to 6.

#20

neochief - September 12, 2009 - 17:56
Status:needs work» needs review

Okay, so can anybody review patch for 6.x? It suppose to be working.

 
 

Drupal is a registered trademark of Dries Buytaert.