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

Comments

brenk28’s picture

StatusFileSize
new639 bytes

This patch simply puts an additional check in line 304 to prevent this.

karens’s picture

Status: Active » Fixed

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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jamsilver’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new1.55 KB
new1.89 KB

I 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_validate function is executed but looks in the wrong place for it's input and returns early, skipping the step of adding the timezone element to the form value. This value is passed on to date_field_validate where 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.

steven jones’s picture

subscribe.

yched’s picture

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

yched’s picture

Additionally, I was a bit worried about this line in the current date_combo_element_process() :

  $form_state['#field_info'][$field['field_name']] = $field;

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.

karens’s picture

Status: Needs review » Fixed

Yay, 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!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.