Fatal error: Cannot use string offset as an array in sites\all\modules\date\date_elements.inc on line 74

To reproduce, add a Date field, with a Popup to a content-type. My granularity settings are Year, Month, Day with no timezone conversion. Now, go try to create a piece of content.

To fix

Just add $items=array();
somewhere within date_field_widget_form() BEFORE foreach ($process as $processed) on line 74.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wjaspers’s picture

Status: Active » Needs review
FileSize
514 bytes
nevets’s picture

Status: Needs review » Active

Since $items is passed in you probably want

if ( !is_array($items) ) {
  $items = array();
}
wjaspers’s picture

Status: Active » Needs review
FileSize
551 bytes

Good catch. I didn't notice it in the method signature.
Ideally, the method signature should enforce the array, but, I'm not about to go hacking away at the entire module. In a quick test, I tried enforcing an array in the method signature, but it didn't work.

The patch attached is as you mentioned above.

KarenS’s picture

Status: Needs review » Postponed (maintainer needs more info)

I've never run into this issue and the Field module is responsible for passing in $items, which should never be missing and should always be an array.

If this is still an issue, I need details on how to reproduce it.

wjaspers’s picture

Status: Postponed (maintainer needs more info) » Fixed

As of recently, I haven't run into the problem again (on D7-dev).
I'll keep an eye out if it resurfaces, though.

Status: Fixed » Closed (fixed)

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