Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
comment.module
Priority:
Normal
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
11 Aug 2009 at 12:51 UTC
Updated:
3 Jan 2014 at 00:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
berdirThe & is not necessary, in fact, it results in a warning in PHP 5.3
Comment #2
claudiu.cristeaYes... You're right...
Updated and set back to "needs review"
Comment #3
moshe weitzman commentedMakes perfect sense. Consistency++. And useful too.
Comment #4
webchickActually, I think it makes more sense to run this op after the fields have been attached. This is consistent with where our alter hooks are elsewhere.
Not quite proper grammar. Probably just:
// Change the comment object before it is saved.
However, it'd be nice to have an actual use case here. What's your motivation behind rolling this patch? What specifically are you trying to do in op presave? Can you make it a 2-3 line example here?
This review is powered by Dreditor.
Comment #5
yched commented"run this op after the fields have been attached"
+1. Node module runs hook_node_* after field_attach_*.
Also, those two lines shouldn't be grouped under the same "// Allow modules to alter the comment before saving." comment.
Comment #6
claudiu.cristeaAfter submitting the patch, I was thinking too to place the hook call after fields were attached... It makes perfectly sense to have the comment object "ready" before presaving ops. Updated the patch (also the grammar issue).
@webchick
I want to perform some operations on data before data is stored in the DB. An example is the module Safe HTML. For node I used
$op == 'submit'(5.x) and$op == 'presave'(6.x). For comments I had to run 2 additional queries (onhook_comment(),$op == 'insert'&$op = 'update') after the comment body was stored in the DB because I cannot intercept the comment before INSERT or UPDATE. And, yes... there is also a matter of consistency between Drupal objects.Comment #8
claudiu.cristeaRetrying...
Comment #9
eojthebraveThe example hook_comment_presave() should have some example code in it that shows how one might alter the $comment object and then return it. See hook_node_presave() as an example.
Otherwise, +1, and the rest of the patch looks good.
Comment #10
claudiu.cristeaOK. Added also a simple example...
Comment #11
moshe weitzman commentedThanks. RTBC.
Comment #12
webchickCommitted to HEAD. Thanks, Claudiu! :)
Marking "needs work" because this needs to be documented in the 6 to 7 upgrade guide. Once this is done, please mark back to "fixed."
Comment #13
eojthebraveI think the example hook_comment_presave() code is still a little off. This line,
+function hook_comment_presave($comment) {Should show that the $comment variable needs to be passed by reference,
&$comment, if you don't pass by reference any action taken on the $comment object inside your presave hook will be lost.Comment #14
webchickeojthebrave: Actually, no. Objects no longer need the & to be passed by reference as of PHP 5 and this will in fact create a warning in PHP 5.3.
Comment #15
eojthebrave@webchick, good to know. Thanks.
Comment #16
claudiu.cristeaI've updated the documentation but I don't understand what's the deal with those categories UNSTABLE-x, so I posted my piece in the top of the list at http://drupal.org/update/modules/6/7#comment_presave_hook
Comment #17
berdirYou should do the opposite and add it to the end :)
Comment #18
claudiu.cristeaWell... it was not obvious :)
Moved to the bottom.
Comment #19
claudiu.cristeaWell... it was not obvious :)
Moved to the bottom.