I'm not a big fan of comment subjects, so I disabled them on my site. However, in doing so, when a new comment comes in, on my "Administer > Comments" page, there wasn't anything in the "Subject" field. So, this patch fixes that.
Here's what it does:
* If the submitted comment doesn't have a subject, it takes the first 25 characters of the comment body itself to create a Subject (just for this admin view)
* I also added some strip_tags to the call creating the "title" attribute of the href (so that comments that start out with a link or some other HTML will look better when you hover over the link on the admin screen).
There wasn't anyone really asking for this (that I know of), but it greatly helps me, since I don't use comment subjects. Hopefully it's useful for someone else.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | subject_comment.patch | 4.26 KB | Tobias Maier |
| #5 | comment_subject-41843_0.diff | 2.36 KB | Cvbge |
| #3 | new_comment.patch | 2.14 KB | billturner |
| comment_module.patch | 1.42 KB | billturner |
Comments
Comment #1
dries commentedCan't we write that shorter with less duplication?
Comment #2
Cvbge commentedThere's also a problem with 'recent comments' block. Without a subject you can't click on the item.
Comment #3
billturner commentedI think I've made the code a little cleaner (reduced some code duplication) per Dries, and I've also made a similar change to the Recent Comments block code which does the same thing. New patch is attached to this message.
Comment #4
Tobias Maier commentedis it not possible to set the subject regardless if the subject is disabled?
Comment #5
Cvbge commentedI think it is... in fact comment_validate() seems to be doing it... Don't know why it's not working.
Anyway, I've changed the patch a bit: stolen some code from comment_validate() and reworded a bit. I'm not sure if the strip_tags(check_markup()) is done correctly, but test show it's all ok.
Comment #6
Cvbge commentedAnother thing: it does not work too well, if the comment body is empty.
In theory body is required, but if you enter a couple of spaces, it's accepted. That's a bug in comment module.
Comment #7
Cvbge commentedAnother problem: in admin/logs the subject is not listed. It says "Comment: added ." [it's translated so I don't know the exact english text]
And for setting comment subject on submission: yes, but that will work only for new comments. We would have to update all old comments without subjects.
Comment #8
Tobias Maier commentedanother error because of this (comment subject unactivated):
if you change the comment viewing options to
"Threaded list - collapsed" or "Flat list - collapsed" there is no title too so you cant click and view them
Comment #9
dries commentedIn Drupal 4.6, the subject was set when the comment was submitted. On input, rather than on output. There shouldn't be empty comment subjects in your database.
Comment #10
Cvbge commentedI probably have them because I'm using HEAD ;)
I could update them with sql of course, if 4.6 is ok.
Comment #11
Tobias Maier commentedI spent a little bit time to investigate this.
the subject is created out of a few letters of the comment if he is empty.
you can see this working at the comment preview
but if you save it it wont be saved...
why?
therefore you have to look at
comment_form_validate()comment_validate() returns an array of all form values and it uses a reference
&of $form_valuesbut what happens with the updated $form_values? they get lost.
I looked on drupaldocs.org for other _validate functions and I found just one which changes some values
and this one goes another approach which I used too:
I hope it is no problem that
$form_valuesis one of the arguments and will be overwritten through theglobal $form_valuesthe rest of the patch is there that if the subject is disabled, that it does not get shown (a change for all themes)
Comment #12
Cvbge commentedAFAIK you can't change form values from _validate().
But clearly there is a need for such actions. So either we should allow _validate() to change content, or maybe we could add some new hook, e.g. _fix() that would be executed before _validate() and would fix some values?
Comment #13
chx commentedsure thing it's called $form['#after_build']
Comment #14
Tobias Maier commentedbut then this validation functions in HEAD are used the false way too:
cu tobi
Comment #15
killes@www.drop.org commentedSounds like a bug report to me. Does this still happen?
Comment #16
drummNope. I've had comments with no subjects showing up properly on delocalizedham.com for awhile now.