Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
comment.module
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
16 Nov 2008 at 17:16 UTC
Updated:
7 Jul 2009 at 14:00 UTC
Jump to comment: Most recent file
it's time to bring comment module out of the dark ages here. attached patch refactors the comment validate/save functions to be more in line with node validation/saving. most importantly, it puts form-specific validation/submission logic in the form validate/submit handlers, and makes comment_validate() and comment_save() truely programatic functions.
one other change of note is that values for comment_validate() and comment_save() are passed by reference, which is especially nice for comment_save(), and you get the entire adjusted $edit array to work with, and not just the new $cid.
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | comment_save_refactor.patch | 17.37 KB | hunmonk |
| #17 | comment_save_refactor.patch | 17.51 KB | hunmonk |
| #11 | comment_save_refactor.patch | 18.06 KB | hunmonk |
| #8 | comment_save_refactor.patch | 18.38 KB | hunmonk |
| #6 | comment_save_refactor.patch | 18.37 KB | hunmonk |
Comments
Comment #1
webchickIn going through this patch we found all kinds of odd things that look like they've been there since the Drupal 4.5 days. If this passes all the tests ;) it seems like a good clean-up to modernize comment module quite a bit and eliminate some of the mega-frustrating inconsistencies between the comment and node modules.
Comment #2
catchLooks like a good clean-up. Do we want to go the whole hog and make comment_save take an object? Not necessarily in this patch of course.
Comment #4
hunmonk commentedi'd prefer to do this incrementally. it truely sucks that comment module's validation and save functionality is this far behind, so let's take this first step to make it more usable, then we can continue to improve more in subsequent fixes.
Comment #5
hunmonk commenteddangit! the bot posted while i was writing mine up. setting back to the right status.
Comment #6
hunmonk commentedre-rolled for latest HEAD. this one passes all the comment tests on my local install, so let's give 'er a whirl...
Comment #7
berdirMinor CS issue..
where should be on the next line.
Patch looks great. Convert $comment/$edit consistently to an object in a follow-up would be great too, as it would help to clean up the comment hooks.
Comment #8
hunmonk commentedre-rolled w/ the CS fix in #7
Comment #11
hunmonk commentedre-rolled to keep up with HEAD
Comment #12
catchLooks fine to me.
Comment #13
chx commentedYes it is good
Comment #14
webchickEr. Guys? In the future, can you please post more substantiative reviews than "looks good"? I have no idea if you actually read the patch in detail or not, so I have to assume you didn't.
While it's definitely better to get a full comment object than merely a cid, this differs from node_save(), which doesn't return anything. The value that's passed in by reference is just referenced later on. For example:
Of course, if you remove the return value then this:
has to change to this:
However, $edit is a more descriptive variable name since we are talking about form values here. I guess what we need is a follow-up patch so that node_save() returns a $node object as well. This'll be a nice DX improvement.
should be 'comment-' since there's no interpolation.
The changes to comment_validate() confuse me. http://api.drupal.org/api/function/hook_comment_validate/7's example code shows that the array coming in is a set of form values, and that the correct response is to form_set_error() if something's amiss. Yet, we remove all of comment module's native validation, which includes form_set_error()s handling to comment_form_validate(), and only call contrib modules' validation handlers in comment_validate? That doesn't really make any sense. Shouldn't all or nothing of this code be moved out?
Looking at http://api.drupal.org/api/function/node_validate/7, the form_set_error() code remains in the node_validate function. So I would keep it in comment_validate() as well.
Comment #15
berdirThe difference is that $node is an object, while $comment is still an array and we thought that it is better to do the array -> object conversion in a later patch as it would make this quite big. After the conversion, we get by reference for free and it will also help to fix the hook_comment_$op() hell ;)
Comment #16
catchWhat Berdir said in regards to comment save.
should be 'comment-' since there's no interpolation.I don't understand this -
comment-is in the patch already?Leaving needs work for the validate comments.
Comment #17
hunmonk commentedthanks for everybody's thoughtful feedback so far!
this patch should address the outstanding issues from webchick's review:
Comment #18
catchMore in-depth review:
This should use the new lovely comment permalinks - comment/$cid#comment-$cid - looks like I missed this one in the patch :(
Same with this one
looks like this wraps at less then 80 chars?
I'm pretty sure both of these come under "I'm just moving code around, not my fault", so don't think they should stop the patch getting in and hence not setting CNW.
Comment #19
moshe weitzman commentedsubscribe ... lets not nitpick this one too long. the net improvement is huge here, even if we mess up some whitespace and leave an inconsistency utouched.
Comment #21
hunmonk commentedlooks like the last commit to comment module included a whitespace change, which caused my patch to fail testing. here's a re-roll.
while i was re-rolling, i decided to go ahead and fix the issues in #18 as well -- other than that, everything else is unchanged.
Comment #22
moshe weitzman commentedRead it over and it all makes sense. Thanks for showing comment module some love.
Comment #23
webchickGreat stuff. Committed to HEAD! :)
These API changes need to be documented in the 6.x to 7.x upgrade guide
Comment #24
webchicktagging
Comment #25
hunmonk commentedupgrade documentation written.