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 = [];
}
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | views-n3256110-8.patch | 740 bytes | damienmckenna |
| #7 | views-display-warning-3256110-7.patch | 708 bytes | Andrei Haurukovich |
| #6 | views-display-warning-3256110-6.patch | 708 bytes | Andrei Haurukovich |
| #2 | 3256110_initial_patch.patch | 525 bytes | Lms300 |
| ViewsIssue.png | 175.79 KB | Lms300 |
Comments
Comment #2
Lms300 commentedComment #3
Lms300 commentedComment #4
damienmckennaThanks for reporting the bug and providing a possible patch.
Let's see what the testbot says.
Comment #5
Andrei Haurukovich commentedI got the same errors during clearing a cache
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=NULLThe 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.Comment #6
Andrei Haurukovich commentedComment #7
Andrei Haurukovich commentedCorrect order of checking
Comment #8
damienmckennaRerolled.
Comment #9
damienmckennaComment #10
renatog commented#8 really makes sense.
&& isset($this->localization_plugin->view->display)+1 to RTBC. Thank you so much everyone
Comment #12
damienmckennaCommitted. Thanks everyone.