0

I'd like to make some changes to a new comment programatically. I'm using the following code:

function MYMODULE_comment_presave($comment) {
    $user = user_load($comment->uid);
    $uid = $user->uid;
    // if ($comment->is_new) {
        $comment->field_image['und'][0]['fid'] = $user->field_image['und'][0]['fid'];
        }
    // }
}

I don't know how I can check whether the comment that's about to be saved is new or edited. $comment->is_new doesn't work.

How can I solve this?

1 Answer 1

0

Use hook_comment_insert() instead, that should work.

4
  • You'd have to let me know what your logic is inside the hooks, then :)
    – Ollie
    Feb 20, 2014 at 23:16
  • So, basically, you're trying to display the user avatars on the comments? Try looking into the file_load function. You can probably do this in the comment template file, rather than saving it to the comment entity, as well. In order to do something to new comments only, you'd use hook_comment_insert(), though!
    – Ollie
    Feb 21, 2014 at 12:05
  • Indeed, that's what I'm trying to do (see: drupal.stackexchange.com/questions/104123/… and drupal.stackexchange.com/questions/104158/…). Maybe file_load can help me in solving the second question. In this case, however, hook_comment_insert really doesn't save any edits to the comment: the field may be an image field, integer field or whatever.
    – Jeroen
    Feb 21, 2014 at 12:28
  • hook_comment_insert doesn't execute on updates, it is only executed when you insert a new comment. To print the avatar, see my comment on your other question :)
    – Ollie
    Feb 21, 2014 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.