When using a Date field with Comment Alter, the UTC offset will be added to the Date on every comment (regardless of if you changed it or not). For example, I'm in UTC-0600, so on every comment 6 hours are subtracted the Date field.
I've spent many, many hours trying to track this down and here is what's happening:
Date adds a special #element_validate function which checks $form_state['input'][$field_name] to determine if the date field is completely empty. If so, it exits early and won't setup some vital timezone information. Unfortunately, the data is actually at $form_state['input']['comment_alter_' . $field_name] so it finds nothing AND #element_validate happens so early, that we have no chance to rewrite $form_state.
I have a patch that will fix this for Date fields (and only Date fields), but it is a terrible hack! Therefore I'm going to post the patch here, but I don't intend to commit it yet because I want to try and persue a different solution if possible.
Basically, the root cause is that we are setting up the field aliases so that the same field can exist on the comment form multiple times. We have a special function that will rewrite the $form and $form_state back, but it won't work with ANY field that use a #element_validate. This simply isn't possible with Drupal's Form API!
To me, this is just another good reason that we should stop aliasing the fields, and simply prevent the user from using the same field twice. This feature has created so many problems and added so much ugly code to Comment Alter, I think we should remove it.
Ok, I'll attach the hackity patch in a moment (once I have this issue's nid)...
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | comment_alter-date-timezone-2197163-2.patch | 2.19 KB | dsnopek |
| #1 | comment_alter-date-timezone-2197163-1.patch | 2.11 KB | dsnopek |
Comments
Comment #1
dsnopekHere is the patch.
Comment #2
dsnopekWe're going to fix this in a much cleaner way: #2193003: Remove feature to use same field twice (and associated hacks)
Comment #3
dsnopekI hate to update this patch (because it's terrible! ;-)) but I need to make a small fix so this can get included in Open Atrium before the real fix here gets merged: #2193003: Remove feature to use same field twice (and associated hacks)