By archard on
All I want to do is alter properties of the links displayed in comments. This is very easy to accomplish if you want to alter a node's links, but there doesn't seem to be any equivalent for comments... no hook, nor preprocess function. The only way I can imagine doing it is doing some kind of string replacement trickery inside the comment's template preprocess function, because the links are passed to it as straight markup, rather than an array or something that can be easily modified.
Am I missing something here? Or is there really no way to alter a comment's links?
Comments
Kind of late, but in case any
Kind of late, but in case any body else would struggle with this issue...
There is no way how to alter comment links through hook, so you need to hack it in HOOK_preprocess_comment() as follows:
"It's never too late to do
"It's never too late to do well" (translated from a french proverb)
Thanks divamys for your good input. It saved me from patching the "comment.module" as a last resort. It's weird there's still no comment link_alter hook implemented despite the several requests in the forum.
I tried before with no luck to catch the theme_comment call but from there after altering the links, I couldn't redirect the call to the theme engine (D6 dont provide anymore the "_phptemplate_callback" function).
Is there really no other way but to have the comment links rendered twice?
Sorry, but at second thought,
Sorry, but at second thought, divamys solution is missing one essential point. The comment_links() function doesn't invoke hook_comment() thus any module action on comments is lost. Even so, it wouldn't be a good idea to pass through all modules comment hook twice.
Therefore, I propose another working option, ugly but simple and efficient in my case: with a couple of lines in template.php (4 in my case), de-render $variables['links'] back to the Drupal standard link array type. Then do any wanted link alteration and finally theme back the link array to $variables['links']. This solution is fast, without any system call but the theme_link function. It even allows to act as well on extra module links.
Hope that will help some :)
Although it's possible, I'm
Although it's possible, I'm not sure how often not invoking hook_comment from comment_links would present an issue. Surely only in cases where other modules have added extra links to the links for the comment? For standard comment links, you're only going to override them anyway with whatever solution you come up with (that's the point of this issue, isn't it?). comment_links would seem to be a very inexpensive function - there's only one call to node_load and that's for a node that would already be cached anyway.
On the other hand, if I understand you correctly, you propose to run a function on all links that are themed? When you say "de-render $variables['links'] back to the Drupal standard link array type" what exactly do you mean? Maybe you could post the whole function that you altered here to demonstrate.
Ideally, it would be great to have a comment_link_alter in core wouldn't it ;)
theme comment de-render
In order to simulate a comment_alter hook, I added the following code in phptemplate_preprocess_comment hook:
< call your comment_alter hook here >
The last preg_replace '|amp|' is needed to correct any javascript attribute which are html encoded in the theme function (through the drupal_attributes() call).
The main regex may need somehow to be tuned to match some specifics configurations.
I use such comment link alteration for a website (french/german) where I've installed the excellent advanced forum to have the comment links being consistent with the node links.
n.b idea of comment_link_alter hook is a long term ride ;)
I wanna add another button to
I wanna add another button to links "quick edit" with class='popups', but I don't know how to achieve this
I've been trying change contactlink.module into my needs, but I'm getting error "call to undefined function comment_load" (upon replacing user_load with it):
There is no comment_load but
There is no comment_load but if you have a look at the api entry for hook_link, you'll find the answer there:
http://api.drupal.org/api/function/hook_link/6
If $type is 'comment', the second parameter, $object, will be the comment itself so something like this should work (untested):
Also, it looks to me that the default value in your _form_alter function should be:
It's working but instead
It's working but instead /comment/edit/123 I'm getting incorrect address /comment/edit/
My bad, line should
My bad, line should be:
Thank You very much! ;-)
Thank You very much! ;-)
One more thing the Quickedit is now appearing for all comments, even if user didn't posted them, which is wrong :/
OK, this is the last time
OK, this is the last time that I'll help and then you're on your own ;) My advice is to use api.drupal.org wherever possible, look in existing Drupal code (especially core) for solutions to similar problems, and maybe read the Pro Drupal Development book which is very good.
So to your problem. What you want to do is add another check to your 'if' statement to see whether the comment author is the same as the logged in author. You already have a reference to the logged in author, ie. the line 'global $user', so this is easy. Usually you'll also want to add the ability for someone with the correct permissions to make changes too, eg. a site admin, moderator, etc., so it's a good idea to look on the user permissions page (/admin/user/permissions) to see if there's an existing permission that's relevant. In this case, there's one called 'administer comments'. You can check if the logged in user has this permission to with the function 'user_access'. So try this:
Hi I was fiddling around with
Hi
I was fiddling around with user_access before, but couldn't make it right.
Thank You v. much again ;-)
a solution
In my module comments_og I do something like the following:
So there is a link alter for comments...!
Yes, hook_link_alter works now
Yes, hook_link_alter works now. I'm pretty sure it wasn't working for comments in threads though until this patch was committed.