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.

Comments

dries’s picture

Priority: Minor » Critical

Can't we write that shorter with less duplication?

Cvbge’s picture

There's also a problem with 'recent comments' block. Without a subject you can't click on the item.

billturner’s picture

StatusFileSize
new2.14 KB

I 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.

Tobias Maier’s picture

is it not possible to set the subject regardless if the subject is disabled?

Cvbge’s picture

StatusFileSize
new2.36 KB

is it not possible to set the subject regardless if the subject is disabled?

I 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.

Cvbge’s picture

Another 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.

Cvbge’s picture

Another 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.

Tobias Maier’s picture

another 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

dries’s picture

In 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.

Cvbge’s picture

I probably have them because I'm using HEAD ;)
I could update them with sql of course, if 4.6 is ok.

Tobias Maier’s picture

StatusFileSize
new4.26 KB

I 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()

function comment_form_validate($form_id, $form_values) {
  comment_validate($form_values);
}

comment_validate() returns an array of all form values and it uses a reference & of $form_values
but 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:

function comment_form_validate($form_id, $form_values) {
  global $form_values;
  $form_values = array_merge($form_values, comment_validate($form_values));
}

I hope it is no problem that $form_values is one of the arguments and will be overwritten through the global $form_values

the rest of the patch is there that if the subject is disabled, that it does not get shown (a change for all themes)

Cvbge’s picture

AFAIK 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?

chx’s picture

sure thing it's called $form['#after_build']

Tobias Maier’s picture

but then this validation functions in HEAD are used the false way too:

cu tobi

killes@www.drop.org’s picture

Version: 4.7.0-beta2 » 4.7.0
Category: feature » bug
Priority: Critical » Normal

Sounds like a bug report to me. Does this still happen?

drumm’s picture

Status: Needs review » Closed (duplicate)

Nope. I've had comments with no subjects showing up properly on delocalizedham.com for awhile now.