I've been trying to figure out why I can't alter comment's links (delete, edit, reply), and it turns out that hook_link_alter isn't implemented for comment links, even though they're built using hook_links!
Seems a little inconsistent to me.
Now, I tried patching comment.module to implement it, but then I realized that the comment object is missing a type, which makes it impossible to distinguish it from a $node inside xxx_link_alter().
So, it looks like comment.module needs some tweaking, or hook_link_alter needs some rethinking.
My first impulse is to add a type property to comment so it can be passed to hook_link_alter, and you can distinguish it from a $node.
Your thoughts are welcome on this.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | comment_link_alter2.patch | 2.42 KB | whisk |
| #1 | comment_hook_link_alter.patch | 8.78 KB | moonray |
Comments
Comment #1
moonray commentedHere's a quick patch I wrote up to get things rolling.
Comment #2
RobRoy commentedIf you were going to go that route, you should just define comment->type = 'comment' in theme_comment_thread_expanded instead of in every db_query. ;)
But, we definitely need a proper solution for 6.x-dev. Why do we need a type in there on the $node object? If type is not specified currently, only hook_link_alter implementations that explicitly check that will not match comments since this isn't currently working for comments themselves. We should probably add a $type param to hook_link_alter itself to specify 'comment', 'node', etc. kinda like $op for hook_taxonomy. But we'll need to pass the $node in for comment links as well...
Comment #3
Gman commentedI agree that some kind of $type variable needs to be implemented in hook_link_alter, just as it is for hook_link. The ability to remove certain links from comments (maybe on a per node-type basis) is really needed. Many modules add those links to all node-types, but a site may only want them on blog and forum comments, without affecting the node links. Adding the $type in the hook_link_alter function will allow such implementations.
Comment #4
Stefan Nagtegaal commentedIs this still an issue in head (drupal 6)? I thought Gurpartap made a patch for this, some while back and got committed.
Comment #5
eaton commentedThere's no way to fix this without breaking existing implementations, unfortunately. If we broaden the coverage of this function existing code will choke because it's only written to handle incoming nodes.
We should, in the future, expand this to cover nodes, comments, and users. Passing in the type of the object as a third parameter to drupal_alter() would probably be the best solution.
Comment #6
catchI just ran into this in 5.x. Marking back to active.
Comment #7
mpg commentedplease help...
it would be nice to change the comment module "comment" link based on the page -- blog post, review or comment so that you could have the link say "comment on this blog" if it is a blog or "review this item" for a review page --
Is this currently possible in 5.5?
thanks you for your reply, this one has been stumping me for a while.
Comment #8
catchThere's a patch here. Also just closed out this dupicate, which has both a patch and a workaround: #169890: hook_link_alter multiple comment view patch
Comment #9
whisk commentedPatch in issue #169890: hook_link_alter multiple comment view patch worked great for my 5.x installations (thanks, subspaceeddy!). But hook_link_alter still isn't completely consistent. It invokes for nodes and comments, but in both cases node object is passed, and it is impossible to retrieve comment object.
I've rewritten the patch a little, so comment.module passes comment object to hook_link_alter. Usage of hook_link_alter changes as following:
In my case, it doesn't affect third-party modules, but thorough check is required...
This patch allowed me to write a tiny UI module with 'approve', 'hide', 'approve and reply' comment links.
Comment #10
dave reidThis may have changed significantly now that hook_link_alter now only works on comment links. See #339929: Move node links into $node->content.
Comment #11
gregglesAgree with Dave Reid in #10. This is already done for 7.x and since it's a change to the API I think it should probably be "wont fixed" for 6.x or earlier.
Comment #12
catchIt's not done in D7, but putting to postponed on #451272: Rename or remove or do *something* with hook_link() so we can close it once that's completely resolved.
Comment #13
damien tournoud commentedhook_link_alter() only works for comments now.
Comment #14
michelleJust ran into this old issue. For anyone else that stumbles on it, have a look at #374463: Alter comment links.
Michelle