Similar issue: #2889759-11: Exposed Date Filter - PHP 7 Error
Steps to replicate:
Standard Install. PHP 7.1.
- Exposed Date Filter for Month/Year
- Table format
- Clickable / Sortable Table Columns
- No not Apply any filters and Sort (by clicking column heading)
If you sort by any field you get this error: Cannot create references to/from string offsets in drupal_array_set_nested_value()
If you apply a filter first, then sort: No issues.
With applying filters: URL looks something like this: ?field_date_value[value][month]=&field_date_value[value][year]=
Without applying filters: URL looks something like this: ?field_date_value[value]=
In the first case with the error, if i manually change the URL to look like the second case where there is no error (i.e. ?field_date_value[value][month]=&field_date_value[value][year]=&order=title_1&sort=desc). No issues/errors.
Stack trace
Error: Uncaught exception 'Error' with message 'Cannot create references to/from string offsets' in web/includes/common.inc:6796
in drupal_array_set_nested_value called at web/includes/form.inc (2098)
in _form_builder_handle_input_element called at web/includes/form.inc (1865)
in form_builder called at web/includes/form.inc (1927)
in form_builder called at web/includes/form.inc (1927)
in form_builder called at web/includes/form.inc (1927)
in form_builder called at web/includes/form.inc (886)
in drupal_process_form called at web/includes/form.inc (386)
in drupal_build_form called at web/sites/all/modules/views/plugins/views_plugin_exposed_form.inc (169)
in views_plugin_exposed_form::render_exposed_form called at web/sites/all/modules/views/includes/view.inc (1003)
in view::build called at web/sites/all/modules/views/plugins/views_plugin_display_page.inc (238)
in views_plugin_display_page::execute called at web/sites/all/modules/views/includes/view.inc (1385)
in view::execute_display called at web/sites/all/modules/views/views.module (600)
in views_page called at web/includes/menu.inc (527)
in menu_execute_active_handler called at web/index.php (21)
As suggested here: #2313517: Cannot create references to/from string offsets nor overloaded objects changing the last parameter of drupal_array_set_nested_value to TRUE such that drupal_array_set_nested_value($form_state['input'], $element['#parents'], NULL, TRUE) in includes/form.inc resolved the issue, but as stated in that thread may cause other issues/regressions and it is preferred for the offending module to resolve.
A possible solution may be for the multi-level parameters to be explicitly stated in the URL ?field_date_value[value][month]=&field_date_value[value][year]= instead of field_date_value[value]= for default options (as is done when filtering). If i'm reading the error correctly, it seems like an array is expected, but a string is provided: i.e. field_date_value[value]=2018-04 instead of field_date_value[value][month]=04&field_date_value[value][year]=2018.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | Screenshot 2018-12-12 at 21.56.56.png | 19.03 KB | steinmb |
| #11 | date-2961859-11-retain-date-format-keys.patch | 1.61 KB | solotandem |
Comments
Comment #2
akolahi commentedComment #3
akolahi commentedComment #4
akolahi commentedComment #5
brockfanning commentedI believe I'm seeing the same issue - it seems that sortable table columns are not possible in a View that has an exposed date filter and is running on PHP7. At first glance it seems like it may be a complicated fix in the date module, as I think that if we change the input data structure, then we'd also have to update various other things (like the query) and I would worry about backwards-compatibility. I hope that someone more familiar with the Date module and Views will be able to provide a patch.
Comment #6
daniel_j commentedI attached a proposed patch for this on related issue 2449261.
Comment #7
joseph.olstadComment #8
steinmb commentedComment #9
liam morlandConvert issue references to links.
Comment #10
damienmckennaComment #11
solotandem commentedMy investigation and testing leads me to believe the root problem lies in removing the date format keys (e.g. year, month) from the submitted form values. This is the cause of the invalid click sort links in a view with an exposed date filter using a table style with click sort columns. The initial display of such a view (even with default values for the exposed filters set programmatically such that none are in the URL) will have the invalid click sort links with a query argument like:
date_value[value]=2018On submit of the exposed filter form the click sort links will be correct with a query argument like:
date_value[value][year]=2018The invalid click sort links cause a fatal error in date_select_element_value_callback() in which $date will be NULL instead of a DateObject instance.
The attached patch retains the format keys. My limited testing with this patch revealed no ill effects. Let's see what the automated tests reveal.
Comment #12
damienmckennaI think this could use some tests.
Comment #13
erik.johansson commentedI think I struggle with the same issue. I have a view that shows all nodes of a certain type, with that I have numerous of exposed filters and one of them is a date field. On initial load everything works fine, all nodes are showing and now query parameters exists. But when I use the pager, query parameters for the exposed filters appears in the url and I get a fatal error.
After applying patch supplied by @solotandem in #11 the pagination and filters started to work again! Thanks for that :)
But one thing has changed in the behaviour, I now need to do a filtering before I can see any result. Before the patch Applied I saw all results on initial load.
I debugged the SQL query on the initial view load and i saw that the date was missing a default value, which is set in the settings for the exposed filter.
WHERE (( (node.status = '1') AND (node.type IN ('program')) AND (DATE_FORMAT(STR_TO_DATE(field_data_field_program_start.field_program_start_value, '%Y-%m-%dT%T'), '%Y') = '')Comment #14
steinmb commentedNot sure what is going on here. I was not able to re-produce this. PHP 7.1.14 - Clean install of D7 dev, date dev. Tried pagers, sort by date and export filter by year. Any hint how to re-produce this problem.
Test view export
Comment #15
steinmb commentedIs it because of #2449261: expects an array, not a scalar - Fatal error: Cannot create references to/from string offsets was committed? If so, can any of you take a test instance and re-test the latest version?
Comment #16
daniel_j commented@steinmb, the patch that was applied in #2449261: expects an array, not a scalar - Fatal error: Cannot create references to/from string offsets was designed to resolve the
'Cannot create references to/from string offsets'error. But looking at the patch in #11 above leads me to believe that there is some extra magic going on here?In other words, the main problem is already resolved, but I think there may possibly be some granularity issues remaining, though I haven't experienced those myself.
Comment #17
steinmb commentedPostponing in hope someone come up with a way to re-produce this. If not, perhaps change the issue to address missing tests?
Comment #18
rclemings commentedI don't have a recipe to reproduce this but I have noticed a couple of things that may be clues:
1. If I try to sort a column after the initial page load, with no filters, I get the error. But if I click the submit button ("apply") -- even with no filters actually set -- then I can sort just fine. If I then click "reset" and try to sort, it fails.
2. The date fields on my page are all profile2 fields.
Comment #19
anthonylindsay commentedI had this exact issue - could not sort a view with an exposed date filter with PHP7.1.
I can confirm that the issue linked in #6 https://www.drupal.org/project/date/issues/2449261 contained the solution. I upgraded from Date 7.x-2.10 to 7.x-2.x-dev which resolved it for me.
Marking needs review as I suspect this one could be closed off if the fix is as simple as 'update to latest dev'.
Comment #20
rclemings commentedSorry, still not working with the current dev and conditions listed in my previous comment (#18).
Comment #21
steinmb commentedPostponding again. Hard to reproduce and even harder to fix without a way to reproduce it.
Comment #22
solotandem commentedI would suggest closing this issue and instead dealing with #3032835: Validate input to date filter handler.
Comment #23
steinmb commentedI think we should close this. No feedback, no way of re-producing it, fixed for some, addressed in other issues.
Comment #24
steinmb commented