Note: this seems to be specific to PHP 5.6.

Steps to reproduce:

  1. Create a new content view with aggregation enabled and save it.
  2. Add a new display and don't save the view.
  3. Try to add a field to the new display.

During step 3, after selecting the "Aggregation type" and clicking "Apply and continue", an AJAX error will be displayed stating:

Fatal error: [] operator not supported for strings in modules/views/includes/admin.inc on line 2399

Watchdog also records a bunch of PHP warnings and notices starting with:

Warning: Parameter 3 to views_ui_build_form_state() expected to be a reference, value given in views_ui_ajax_form() (line 2949 of modules/views/includes/admin.inc

The problem therefore seems to stem from the call_user_func_array() on line 2949 not passing the $view object by reference to views_ui_build_form_state(). This only seems to be a problem with PHP 5.6; it works fine on 5.5 and 5.4.

Comments

morbiD created an issue. See original summary.

torgospizza’s picture

Ran into this too. What's the best way to fix? Is it simple enough to pass the variable as a reference instead?

g33kg1rl’s picture

I receive this error when trying add a new taxonomy filter on a view with aggregation. Any ideas?

spgd01’s picture

I have exact same issue as #3

skaught’s picture

issue also occurs in php7

in my case we were adding a term reference field.
only had Fatal error: [] operator not supported for strings in modules/views/includes/admin.inc on line 2399

skaught’s picture

Priority: Normal » Major

IMO: major. this stops anyone from being able to build a View.

short term work around: turn of javascript on your browser and build your view.

nickonom’s picture

Status: Active » Closed (duplicate)

Even-though #2823977: Ajax http 500 error using taxonomy to filter view was filed later than this one, it has already working patch for the same problem, so I am marking this as duplicate.

richardp’s picture

Though this is closed, I still found this issue when going through google. I saw the first error, about how you can't use [] operand on string, after updating to PHP7.0.

The other patch mentioned in comment #7 didn't work for me.

I made my own edits to views/include/admin.inc. Starting on line 2391, this is the entire views_ui_regenerate_tab function, including my change:

function views_ui_regenerate_tab(&$view, &$output, $display_id) {
  if (!$view->set_display('default')) {
    return;
  }

  ///////////////////////////
  // Added by RP on 3.20.2018, to fix bug where view kept showing error about how
  // you couldn't use [] on a String.  It's the $output variable.  
  // basically, just make sure the $output var is an array.  If it had a string in it originally,
  // then let's add that in as its first element.
  if (!is_array($output)) {
    $original = $output;
    $output = array();
    if ($original != "") {
      $output[] = $original;
    }
  }
  //////////////////////////////  

  // Regenerate the main display area.
  $build = views_ui_get_display_tab($view, $display_id);
  views_ui_add_microweights($build);
  $output[] = ajax_command_html('#views-tab-' . $display_id, drupal_render($build));

  // Regenerate the top area so changes to display names and order will appear.
  $build = views_ui_render_display_top($view, $display_id);
  views_ui_add_microweights($build);
  $output[] = ajax_command_replace('#views-display-top', drupal_render($build));
}
damienmckenna’s picture

Status: Closed (duplicate) » Needs review
StatusFileSize
new2.76 KB

Ok, lets try this then.

vdupom’s picture

At line 2497 is_array() is missing the parameter, I believe it should be
if (!is_array($output)) {

Now adding a field does nothing in the Views UI and an error is logged:
Warning: is_array() expects exactly 1 parameter, 0 given in views_ui_regenerate_tab() (line 2497 of ..../sites/all/modules/contrib/views/includes/admin.inc).

jenlampton’s picture

StatusFileSize
new2.76 KB

Here's an updated patch that contains the recommended fix from #11.

I've also filed a similar issue against Backdrop core:
https://github.com/backdrop/backdrop-issues/issues/3244

g33kg1rl’s picture

Patch #12 fixed the issue on my websites. :)

chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The patch in #12 to admin.inc does not apply to the latest views 7.x-3.x-dev.

Checking patch includes/admin.inc...
error: while searching for:
  array_splice($args, 0, 4);

  $form_state = views_ui_build_form_state($js, $key, $view, $display_id, $args);
  // check to see if this is the top form of the stack. If it is, pop
  // it off; if it isn't, the user clicked somewhere else and the stack is
  // now irrelevant.
  if (!empty($view->stack)) {

error: patch failed: includes/admin.inc:3004
error: includes/admin.inc: patch does not apply
valderama’s picture

StatusFileSize
new729 bytes

A patch with just the meat, and no typo fixes in the comments.

skaught’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 15: views-n2767167-15.patch, failed testing. View results

andrew answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.76 KB

Patch rerolled.

dylf’s picture

Status: Needs review » Needs work
  1. The typehint in the function signature causes a type error when the $output variable is a string.
  2. $output is expected to be an array of ajax commands. This doesn't seem like a proper solution.