Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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=
Comment | File | Size | Author |
---|---|---|---|
#2 | 2375705-2--date_validation_value--POC.patch | 1.54 KB | drunken monkey |
Comments
Comment #1
vijaycs85have 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).
Comment #2
drunken monkeyI 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:
date_views_filter_handler_simple
handler sets an exposed value form with adate_select
(ordate_text
) value element.date_select_validate()
/date_text_validate()
.raw_exposed_input
property – including the altered date filter value.raw_exposed_input
property is passed as additional GET parameters for the link.date_filter[value]
instead ofdate_filter[value][year]
) gets included.$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.
Comment #3
herd45 CreditAttribution: herd45 commentedThe patch fixed the problem.
Comment #4
joachim CreditAttribution: joachim commentedWith 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.