When you have a form with a '#type' => 'date_popup' element, the value of said element in the form state differs in structure based on the scenario.

  • Element left empty: NULL (this is okay)
  • Element filled out correctly: datetime string (this is okay)
  • Element filled out incorrectly: array with 'date' and 'time' keys (this is not okay!)
  • Element loaded through Paragraphs module: array with 'date' and 'time' keys (this is not okay!)

The reason is that the date_popup element uses the common trick of having multiple elements within its widget and then massaging that widget's multiple inputs back into one output. This is almost always done in the validate handler by calling form_set_value().

However, because of all the conditional return statements in date_popup_validate(), form_set_value() is never called when something goes wrong, leading to the form state containing unexpected data; i.e.: an array.

Solution: Either delete all of those return values or -if they control the current logic- accompany all of them with a form_set_value() that sets a good value for the scenario at hand.

P.S.: haven't checked the other widgets provided by Date but they may contain the same offending logic.


kristiaanvandeneynde created an issue.