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.

Comments

akolahi created an issue. See original summary.

akolahi’s picture

Issue summary: View changes
akolahi’s picture

Issue tags: +PHP 7.1
akolahi’s picture

Title: PHP 7.1 Exposed Date Field Issue WSOD Fatal Error » PHP 7.1 Exposed Date Field Issue WSOD Fatal Error: Cannot create references to/from string offsets
brockfanning’s picture

I 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.

daniel_j’s picture

I attached a proposed patch for this on related issue 2449261.

steinmb’s picture

Issue summary: View changes
liam morland’s picture

Issue summary: View changes

Convert issue references to links.

solotandem’s picture

Status: Active » Needs review
StatusFileSize
new1.61 KB

My 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]=2018

On submit of the exposed filter form the click sort links will be correct with a query argument like:

date_value[value][year]=2018

The 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.

damienmckenna’s picture

Issue tags: +Needs tests

I think this could use some tests.

erik.johansson’s picture

I 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') = '')

steinmb’s picture

StatusFileSize
new19.03 KB

Not 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.

views filter date

Test view export

  • Field: field_date
$view = new view();
$view->name = 'dates';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Dates';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Dates';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
$handler->display->display_options['pager']['type'] = 'mini';
$handler->display->display_options['pager']['options']['items_per_page'] = '2';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'field_date' => 'field_date',
  'edit_node' => 'edit_node',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_date' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'edit_node' => array(
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Date */
$handler->display->display_options['fields']['field_date']['id'] = 'field_date';
$handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
$handler->display->display_options['fields']['field_date']['field'] = 'field_date';
$handler->display->display_options['fields']['field_date']['settings'] = array(
  'format_type' => 'short',
  'custom_date_format' => 'Y',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_remaining_days' => 0,
  'show_repeat_rule' => 'show',
);
$handler->display->display_options['fields']['field_date']['delta_offset'] = '0';
/* Field: Content: Edit link */
$handler->display->display_options['fields']['edit_node']['id'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['edit_node']['field'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['label'] = '';
$handler->display->display_options['fields']['edit_node']['element_label_colon'] = FALSE;
/* Sort criterion: Content: Date (field_date) */
$handler->display->display_options['sorts']['field_date_value']['id'] = 'field_date_value';
$handler->display->display_options['sorts']['field_date_value']['table'] = 'field_data_field_date';
$handler->display->display_options['sorts']['field_date_value']['field'] = 'field_date_value';
/* Filter criterion: Content: Date (field_date) */
$handler->display->display_options['filters']['field_date_value']['id'] = 'field_date_value';
$handler->display->display_options['filters']['field_date_value']['table'] = 'field_data_field_date';
$handler->display->display_options['filters']['field_date_value']['field'] = 'field_date_value';
$handler->display->display_options['filters']['field_date_value']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_date_value']['expose']['operator_id'] = 'field_date_value_op';
$handler->display->display_options['filters']['field_date_value']['expose']['label'] = 'Date';
$handler->display->display_options['filters']['field_date_value']['expose']['operator'] = 'field_date_value_op';
$handler->display->display_options['filters']['field_date_value']['expose']['identifier'] = 'date';
$handler->display->display_options['filters']['field_date_value']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
);
$handler->display->display_options['filters']['field_date_value']['granularity'] = 'year';
$handler->display->display_options['filters']['field_date_value']['form_type'] = 'date_text';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'dates';
steinmb’s picture

Status: Needs review » Needs work

Is 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?

daniel_j’s picture

@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.

steinmb’s picture

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

Postponing in hope someone come up with a way to re-produce this. If not, perhaps change the issue to address missing tests?

rclemings’s picture

I 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.

anthonylindsay’s picture

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

I 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'.

rclemings’s picture

Status: Needs review » Needs work

Sorry, still not working with the current dev and conditions listed in my previous comment (#18).

steinmb’s picture

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

Postponding again. Hard to reproduce and even harder to fix without a way to reproduce it.

solotandem’s picture

I would suggest closing this issue and instead dealing with #3032835: Validate input to date filter handler.

steinmb’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
Issue tags: -PHP 7.1, -Needs tests

I think we should close this. No feedback, no way of re-producing it, fixed for some, addressed in other issues.

steinmb’s picture