Use case:
You have node that has a date field and a nodereference field. You fill in your from and to dates, but the to date is not valid, it is before the from date. You go to your node reference field and add a node reference, then click "add another item." Field validation is called at this point. So, when date_field_validate is called, you have an items array, but it is not fully formed at this point. It gets to the items loop and each item is an array, but it doesn't have every expected index yet, so you get notices:
Notice: Undefined index: timezone in date_field_validate() (line 306 of modules/date/date/date.field.inc).
Notice: Undefined index: timezone in date_field_validate() (line 311 of modules/date/date/date.field.inc).
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | date-998220-date-validation-errors.patch | 1.89 KB | jamsilver |
| #4 | date-998220-date-validation-errors-drush-make.patch | 1.55 KB | jamsilver |
| #1 | date-validation-notice-998220-1.patch | 639 bytes | brenk28 |
Comments
Comment #1
brenk28 commentedThis patch simply puts an additional check in line 304 to prevent this.
Comment #2
karens commentedSame issue as #1021512: Errors when using Profile 2 with Date module, which I just committed a fix for. I think this is specific to fields added to users.
Comment #4
jamsilver commentedI came across this issue when a date field was in a field collection, which is a similar form structure to the issues in #1021512: Errors when using Profile 2 with Date module I believe.
The warnings appear because the
date_combo_validatefunction is executed but looks in the wrong place for it's input and returns early, skipping the step of adding thetimezoneelement to the form value. This value is passed on todate_field_validatewhere the warnings appear. This would happen whenever the date combo field wasn't at the top level of the form i.e. if the field was added to another parent element, such as a field collection or profile2 field.Attached are two patches, one for the maintainer and anyone else, and one for drush make.
Comment #5
steven jones commentedsubscribe.
Comment #6
yched commentedI'll leave people confirm whether it fixes the issues in Profile2 and field_collection, but I confirm the code changes in patch #4 - correct application of the core changes brought by #942310: Field form cannot be attached more than once.
Comment #7
yched commentedAdditionally, I was a bit worried about this line in the current date_combo_element_process() :
The same field can be attached at several sublevels within a given form, so blindly sitting at the toplevel of $form_state is not recommended anymore. However, it seems that this '#field_info' property is in fact not used anywhere in the code. Possibly a leftover from D6 (CCK had some $form_state['#field_info'] back then), should be safely removable anyway.
Comment #8
karens commentedYay, thanks! This does indeed fix errors when using a date with Profile 2, didn't test field collections. And the #field_info code was a leftover from D6 that I missed, so I removed that too.
Thanks!