I'm getting a white screen when I sort a View that has an exposed date filter. When I sort the view, the url that is getting the white screen has the following pattern....

?&date_filter[value]=2014&

If I manually replace [value] with [year], the the page loads as correctly.

Also, this only happens when the exposed date filter has not been changed If the exposed date field has been changed, the url has this pattern and works correctly.....

?date_filter[value][year]=2005&&order=

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vijaycs85’s picture

Status: Active » Postponed

have spent sometime on this issue and found that the problem is in views module. So filed #2400959: Fatal error when try to sort with exposed filter. Lets wait until here from views maintainer(s).

drunken monkey’s picture

Status: Postponed » Needs work
FileSize
1.54 KB

I have looked at this now quite closely and I don't think this is really a Views problem. The root cause, as I see it, is that the Date module internally sets a new value for its form element in the validate function which is incompatible with the values structure for the element (expected is an array, which it is also originally, but it sets a string), leading to wrong links being created for click sorts and the pager links. When one of those is then clicked, it leads to the Fatal error: Cannot create references to/from string offsets nor overloaded objects error being triggered and the WSoD (if error display isn't enabled) being returned.

The sequence seems to be the following:

  1. The date_views_filter_handler_simple handler sets an exposed value form with a date_select (or date_text) value element.
  2. The Views exposed form plugin simulates a submit (for reasons unknown to me, but it seems that's just how Views decided exposed forms should work, probably to increase predictability), triggering the element's validation function, date_select_validate()/date_text_validate().
  3. There, the element's value gets changed from an associative array (with elements for year, month, etc.) to a date/time value in string format – probably so that code using the element doesn't have to parse the value array on its own.
  4. After that, Views saves all the (non-FAPI-internal) values in the form state into the view's raw_exposed_input property – including the altered date filter value.
  5. When creating links for sorts, the pager or other purposes inside the view, the raw_exposed_input property is passed as additional GET parameters for the link.
  6. Thus, for all those links, the wrong value structure (date_filter[value] instead of date_filter[value][year]) gets included.
  7. When such a link is clicked, the Form API triggers the above-mentioned error while trying to set the element's default value in $form_state['input']['date_filter']['value']['year'] while $form_state['input']['date_filter']['value'] is already set to a string.

The only thing preventing this error after the exposed filter has explicitly been set (i.e., is present in the URL) is that in theme_pager_link() the GET parameters in the current page's URL implicitly overwrite all passed parameters – without this rather arbitrary choice, this wouldn't ever work.

However, as far as fixing this is concerned, I'm not really sure what to do. Setting the element value to one that's incompatible with the element in some contexts seems like a terribly dangerous thing to do – but since I don't know the Date module too well, I don't know where that decision is already reflected and would need to be changed.
The attached patch is a proof of concept for fixing this issue – for me, it works fine (except that the URL gets a bit uglier) for views and editing field values, but I'm pretty certain that it would break other parts/sub-modules of the Date project, or other further extension modules. Someone more familiar with the Date module would have to go over those and adapt them, too – or, of course, come up with a different solution.

In any case, I hope this helps solve the issue.

herd45’s picture

The patch fixed the problem.

joachim’s picture

With this patch, default values in the exposed filter are lost when using tablesort links. I've filed a patch at #2575921: tablesort links are broken when a view has an exposed date filter with a default value which I think fixes everything.