Problem/Motivation

When executing certain tasks that have as one of it's call stack steps exporting a view, such as clearing caches, the export is not always done in a way that every handler is initialized. This causes some handlers, such as $display, to stay as NULL. Because of this some executions of the process_locale_strings() -> init_display() -> line 488 provide a NULL variable to the array_keys() function, which necessarily expects an array as one of it's parameters, thus causing the following warnings to ensue :

Warning: array_keys() expects parameter 1 to be an array, null given in view->init_display() (line 488 of .../view.inc)
Warning: invalid argument supplied for foreach() in view->init_display() (line 488 of .../view.inc)

Steps to reproduce

This issue might not be reproducible in every Drupal installation, but one way of reproducing it is accessing /admin/config/development/performance and clicking Clear all caches.

Proposed resolution

A simple, palliative solution, would be to include in line 486 or view.inc an if statement to check if $this->display, is not an array. If that is the case, it should be initialized as an empty array before it is fed as parameter to array_keys() :

// Make sure that the display handler is an array
// before iterating through it with array_keys()
if (!is_array($this->display)) {
  $this->display = [];
}

Comments

Lms300 created an issue. See original summary.

Lms300’s picture

StatusFileSize
new525 bytes
Lms300’s picture

Issue summary: View changes
damienmckenna’s picture

Status: Active » Needs review

Thanks for reporting the bug and providing a possible patch.

Let's see what the testbot says.

Andrei Haurukovich’s picture

I got the same errors during clearing a cache

Warning: invalid argument supplied for foreach() in view->init_display() (line 488 of .../view.inc)
Warning: Creating default object from empty value in view->view->init_display

I made some investigation and find out that occures on some views that have localization plugin enabled. For this views view->display is null.
Structure of views looks like $this->view->localization_pugin->view->display=NULL

The root cause most likely - when we enable views localization plugin it's structure has become a recursion ($this->view->localization_pugin->view->localization_pugin->view...) and if our site has a lot of feature overrides and modules localization_plugin display not always loading in time.

So in my opinion it's better to make additional check function process_locale_strings() if isset($this->localization_plugin->view->display) then create an empty array.

Andrei Haurukovich’s picture

StatusFileSize
new708 bytes
Andrei Haurukovich’s picture

StatusFileSize
new708 bytes

Correct order of checking

damienmckenna’s picture

StatusFileSize
new740 bytes

Rerolled.

damienmckenna’s picture

Assigned: Lms300 » Unassigned
renatog’s picture

Status: Needs review » Reviewed & tested by the community

#8 really makes sense.

  1. The patch rerolled applies correctly in the last version of 7.x-3.x
  2. The new verification was added correctly && isset($this->localization_plugin->view->display)
  3. The code is more organized with one condition per line instead of single-line condition

+1 to RTBC. Thank you so much everyone

  • DamienMcKenna committed 2099486 on 7.x-3.x authored by Lms300
    Issue #3256110 by Andrei Haurukovich, Lms300, DamienMcKenna, RenatoG:...
damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed
Parent issue: » #3232189: Plan for Views 7.x-3.26

Committed. Thanks everyone.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.