diff --git a/core/lib/Drupal/Core/Render/RenderCache.php b/core/lib/Drupal/Core/Render/RenderCache.php index 99e2a9a..c33179a 100644 --- a/core/lib/Drupal/Core/Render/RenderCache.php +++ b/core/lib/Drupal/Core/Render/RenderCache.php @@ -340,7 +340,7 @@ public function getCacheableRenderArray(array $elements) { $data['#cache_properties'] = $elements['#cache_properties']; // Store whether any of the cache properties are safe strings. foreach (Element::properties(array_flip($elements['#cache_properties'])) as $cache_property) { - if (isset($elements[$cache_property]) && SafeMarkup::isSafe($elements[$cache_property])) { + if (isset($elements[$cache_property]) && !is_array($elements[$cache_property]) && SafeMarkup::isSafe($elements[$cache_property])) { $data['#safe_cache_properties'][] = $cache_property; } } diff --git a/core/lib/Drupal/Core/Render/RenderCacheInterface.php b/core/lib/Drupal/Core/Render/RenderCacheInterface.php index c0e580b..2d9552f 100644 --- a/core/lib/Drupal/Core/Render/RenderCacheInterface.php +++ b/core/lib/Drupal/Core/Render/RenderCacheInterface.php @@ -44,7 +44,10 @@ public function getCacheableRenderArray(array $elements); * * @return array|false * A renderable array, with the original element and all its children pre- - * rendered, or FALSE if no cached copy of the element is available. + * rendered, or FALSE if no cached copy of the element is available. The + * array contains a '#safe_cache_properties' key detailing any properties + * that were safe strings when the render cache was set. The + * '#safe_cache_properties' is removed once it is used by the render system. * * @see \Drupal\Core\Render\RendererInterface::render() * @see ::set() diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTest.php b/core/tests/Drupal/Tests/Core/Render/RendererTest.php index 978ec7f..01857c9 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererTest.php @@ -695,6 +695,7 @@ public function testRenderCacheProperties(array $expected_results) { 'child2' => ['#markup' => '2'], // Mark the value as safe. '#custom_property' => SafeMarkup::checkPlain('custom_value'), + '#custom_property_array' => ['custom value'], ]; $this->renderer->renderRoot($element); @@ -714,7 +715,9 @@ public function testRenderCacheProperties(array $expected_results) { $this->assertSame($data[$property], $original[$property]); } } - $this->assertArrayEquals(array_merge(['#markup'], Element::properties(array_filter($expected_results))), $data['#safe_cache_properties']); + // #custom_property_array can not be a safe_cache_property. + $safe_cache_properties = array_diff(array_merge(['#markup'], Element::properties(array_filter($expected_results))), ['#custom_property_array']); + $this->assertArrayEquals($safe_cache_properties, $data['#safe_cache_properties']); } /** @@ -727,14 +730,15 @@ public function testRenderCacheProperties(array $expected_results) { public function providerTestRenderCacheProperties() { return [ [[]], - [['child1' => 0, 'child2' => 0, '#custom_property' => 0]], - [['child1' => 0, 'child2' => 0, '#custom_property' => 1]], - [['child1' => 0, 'child2' => 1, '#custom_property' => 0]], - [['child1' => 0, 'child2' => 1, '#custom_property' => 1]], - [['child1' => 1, 'child2' => 0, '#custom_property' => 0]], - [['child1' => 1, 'child2' => 0, '#custom_property' => 1]], - [['child1' => 1, 'child2' => 1, '#custom_property' => 0]], - [['child1' => 1, 'child2' => 1, '#custom_property' => 1]], + [['child1' => 0, 'child2' => 0, '#custom_property' => 0, '#custom_property_array' => 0]], + [['child1' => 0, 'child2' => 0, '#custom_property' => 1, '#custom_property_array' => 0]], + [['child1' => 0, 'child2' => 1, '#custom_property' => 0, '#custom_property_array' => 0]], + [['child1' => 0, 'child2' => 1, '#custom_property' => 1, '#custom_property_array' => 0]], + [['child1' => 1, 'child2' => 0, '#custom_property' => 0, '#custom_property_array' => 0]], + [['child1' => 1, 'child2' => 0, '#custom_property' => 1, '#custom_property_array' => 0]], + [['child1' => 1, 'child2' => 1, '#custom_property' => 0, '#custom_property_array' => 0]], + [['child1' => 1, 'child2' => 1, '#custom_property' => 1, '#custom_property_array' => 0]], + [['child1' => 1, 'child2' => 1, '#custom_property' => 1, '#custom_property_array' => 1]], ]; }