By tormu on
I have a mymodule.module and on it I have the following:
function mymodule_comment($comment, $op)
{
switch ($op)
{
case 'insert':
$to = 'someone@something.com;
$subject = 'New comment added';
$body = 'New comment added to the following page: ......';
drupal_mail('comment-inserted', $to, $subject, $body);
case 'update':
case 'view':
case 'form':
case 'validate':
case 'publish':
case 'unpublish':
case 'delete':
}
}
For some reason this doesn't work at all - it stops showing the existing comments completely! Even I strip everything else out and just do it like below, it does the same.
function mymodule_comment($comment, $op)
{
}
$op seems to be Array at some points, so when I have one comment and print_r($op), it prints out
view
Array
(
[comment_delete] => Array
(
[title] => delete
[href] => comment/delete/3
)
[comment_edit] => Array
(
[title] => edit
[href] => comment/edit/3
)
[comment_reply] => Array
(
[title] => reply
[href] => comment/reply/48/3
)
)
form
What makes this even more frustrating is the exact same implementation code works fine if I change the name of the hook implementation to some other activated module, for example taxonomy_breadcrumb_comment. Then the $op is always a string and never Array and it works all right :O
Comments
Sounds like some other part
Sounds like some other part of your module is altering something it shouldn't, perhaps post the entire thing and I'll look it over?
Pobster
I also tried removing
I also tried removing everything else than the mymodule_comment() and it's the same.
So even if the mymodule.module only contains "mymodule_comment($comment, $op) { }", it messes it up.
Okay well, nothing looks out
Okay well, nothing looks out of the ordinary I guess? So perhaps try looking at another module which successfully implements hook_comment (http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/spam/spam.m...)
I'm not able to upload anything to my test site from where I am at the moment to do any detective work, but it seems though that the spam module works fine (I use it myself)... I'm sure it won't help though as you said that even when the hook doesn't do anything and is just present that the comments are erased? I guess it's still probably going to be quite helpful to look at the spam module code though and see if it does anything else which you haven't thought of?
Pobster
This is the first time
This is the first time Drupal is acting up really bad for me, there haven't been any total WTF moments before but this one sure is..
Yep - even if the whole function is completely empty but introduced, it hides the comments. Nothing fancy done with comment module either.
I've also checked other modules that implement the comment hook, but can't find anything that leads to this problem :(
...
So the name, and only the name, of the function,
mymodule_comment, has some significance --which we need to find out. Drupal recognizes it as somthing; and calls it. It seems that we have accidentally implemented some hook. Printing the call stack would have easily solved the mystery.Usually, when hooks return nothing, it breaks nothing. Let's think. It must be some enigmatic
hook_comment. But thishook_commentisn't a normal hook: it breaks something; it affects something; what we see. Oh, it's easy: (WARNING: spoiler ahead!)You have a theme by the name "mymodule". So when drupal does
theme('comment', $comment, $links)when printing your comments it ends up asmymodule_comment($comment, $links).--
Help save BLOCKQUOTE
correct
Yeah you've got it - I have a theme that is named the same as the module is :P
Any idea how to correct this then? Would it help if I override the comment theming in template.php or so? The site is 97% ready from launching, so I wouldn't like to change the name of the theme, since we have tens of nodes in which some image paths are set to absolute (/sites/all/themes/mymodule/img/....)
3 years later :)
I had the same problem. And I resolved it with renaming mymodule_comment() function to menu_comment(), because menu module does not have this hook. Name conflict was gone.
PS Big thanks to mooffie. I could not imagine what the problem is with this hook.
Holy ****. I never would have
Holy ****. I never would have come to that conclusion. Thanks a million for posting this.