I updated to version 2.8 and am getting the following runtime error:

Warning: Illegal string offset 'year' in date_select_element_value_callback() (line 437 of /var/www/drupal-7.27/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Illegal string offset 'month' in date_select_element_value_callback() (line 437 of /var/www/drupal-7.27/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Illegal string offset 'year' in drupal_array_set_nested_value() (line 6618 of /var/www/drupal-7.27/includes/common.inc).

I believe the warning about common.inc is caused by the date issues before it.

I'm getting these errors for a View page that has a date filter field configured as attached image...

Comments

monaw’s picture

Ok, after some debugging, it appears that the problem is caused by the date_select_element_value_callback() function getting a string (eg "2014-03") for the $input parameter and then handing that parameter to the date_select_input_date() function which expects $input to be an array. This seems like a pretty fundamental functionality for the Date module...

It would be helpful if the date_select_element_value_callback() function is better documented as to the parameters it expects and what is returned.

monaw’s picture

Hmm, I did a quick test and made the $input into an array but that didn't fix my problem...

Please help!

jennifer.chang’s picture

I believe it's a PHP 5.4 compatibility error.

damienmckenna’s picture

Am hitting this error with PHP 5.3.3.

damienmckenna’s picture

Version: 7.x-2.8 » 7.x-2.x-dev

FYI the problem persists in the current -dev release (7.x-2.9-beta2+1-dev).

damienmckenna’s picture

FYI in my case the view works fine on initial load, the error only shows when loading page 2 and only happens if an exposed filter for a date field is passed a value.

damienmckenna’s picture

Component: Code » Views Filter

A little more info:

  • The exposed filter has the granularity set to 'year',
  • It's using a 'select' element,
  • The starting year is hardcoded to a specific number,
  • The ending year is set to "+0 years from now".
damienmckenna’s picture

When the form is loaded first, the $input argument to date_select_element_value_callback() is an array:

array(
  'year' => 2014,
)

When the form is submitted, $input gets passed as a string instead: '2014'

damienmckenna’s picture

I've noticed that the problem doesn't happen if I just manipulate the filters, it is only triggered when I use the pager.

damienmckenna’s picture

I traced it back a bit further, and it isn't just the pager. The exposed filter is built correctly, so the date field has the proper name attribute on the date selector, e.g. "date_filter[value][year]" for the year value. However, inside Views it is using a string value for the date field's default value in the 'exposed_raw_input' array in the $view object inside template_preprocess_views_view(). So it seems that the translation from string to array isn't happening like it should be.

damienmckenna’s picture

Component: Views Filter » Code

So I ended up resolving this by using a preprocess function to fix the value being passed to the pager:

function example_preprocess_pager(&$variables) {
  // The name of the exposed field.
  $field_name = 'the_year';
  if (isset($variables['parameters'][$field_name]['value']) && is_numeric($variables['parameters'][$field_name]['value'])) {
    $variables['parameters'][$field_name]['value'] = array(
      'year' => $variables['parameters'][$field_name]['value'],
    );
  }
}

I've already spent far too long digging into this problem for this site, this bandaid is sufficient for now but obviously it doesn't actually fix the issue.

Lostboy22’s picture

Try logging out and restarting your browser.
If you changed the "Remember last selection", value or removed and recreated the same filter, there is a session cookie that does not get set/cleared.

damienmckenna’s picture

@Lostboy22: On this view I don't have the 'remember' option enabled for any of the exposed fields.

alexdmccabe’s picture

Title: Warning: Illegal string offset 'year' in date_select_element_value_callback() » Pager should be built with view::get_exposed_input(), not $view->exposed_raw_input.
Project: Date » Views (for Drupal 7)
Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Active » Needs review
StatusFileSize
new554 bytes

As far as I can tell, this is actually an issue with Views. Uploading a patch.

The exposed input itself is fine, but the way Views is building the pager it's not properly looking at the exposed input.

damienmckenna’s picture

Status: Needs review » Reviewed & tested by the community

@alexdmccabe's patch resolves the problem I was experiencing on a site and makes the URLs shorter on the initial page because it isn't passing the exposed filter's default values to the pager. Thanks for solving the problem!

colan’s picture

We've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.

If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.

We apologize for the trouble, and appreciate your patience.

alexdmccabe’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new554 bytes

Re-uploading patch to get tests to run per #16.

alexdmccabe’s picture

Status: Needs review » Reviewed & tested by the community

Changing back to RTBC, again per #16.

damienmckenna’s picture

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks!

Status: Fixed » Closed (fixed)

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