Problem/Motivation
On a panelized node, if a block is empty in a region (ie. view block with 0 results), the Panels StandardDisplayBuilder class incorrectly sets cacheable metadata, resulting in multiple 'User error' messages that look like the following: User error: "max-age" is an invalid render array key
To reproduce on clean drupal install (8.1.10) w/ panels 8.x-3.0-beta5, panelizer 8.x-3.0-alpha2 (and all dependencies)
- Create a 'view block' with a filter that will return 0 results (ie. add filter for taxonomy term that no nodes are tagged for
- On the 'block' tab of the view, set 'Hide block if the view output is empty' to 'Yes'
- Place the view block you created with panelizer on a panelized node, and save it
- Clear cache, and then view the node with the empty block
- View DB log to see 'User error: "0" is an invalid render array key', 'User error: "1" is an invalid render array key', etc etc
Proposed resolution
Basically, in panels/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php::136
there is a check for empty blocks, and if they are empty it attempts to set the #cache in the render array for an empty block. However, it incorrectly sets the $block_render_array var, and instead of updating the #cache element in the array, it creates sibling elements with the contents of $content['#cache'], leaving the initial element in $block_render_array blank. The code below is the culprit:
if (isset($content['#cache'])) {
$block_render_array += $content['#cache'];
}
Should be:
if (isset($content['#cache'])) {
$block_render_array['#cache'] += $content['#cache'];
}
Or, alternatively as I've handled in this patch:
$content_cache = $content['#cache'];
if (isset($content_cache)) {
foreach ($content_cache as $key => $cache_item) {
$block_render_array['#cache'][$key] = $cache_item;
}
}
After applying the patch, the array is returned correctly and the 'User Errors' disappear. I'm not sure which approach of the above is preferred.
Remaining tasks
Review/feedback needed
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
panels-display-builder.patch | 943 bytes | trwill | |
|
Comments
Comment #2
trwill CreditAttribution: trwill commentedComment #3
dobrzyns CreditAttribution: dobrzyns at PMMI Media Group commentedI can verify that the errors go away after applying the patch.
I'm not sure which of the approaches is preferred though.
Comment #4
trwill CreditAttribution: trwill commentedComment #5
trwill CreditAttribution: trwill commentedI updated the steps to reproduce after realizing I added a lot complexity with contextual filters and that any 'empty' block (ie view block with 0 results) is enough to reproduce the errors.
Comment #6
lauriiiThis is duplicate for #2812721: Incorrect logic inside of StandardDisplayBuilder could lead to fatal error (followup for #2781897)