$element = [
'#type' => 'container',
'#cache' => [
- 'keys' => ['simpletest', 'drupal_render', 'children_attached'],
+ 'keys' => ['simpletest', 'renderer', 'children_attached'],
],
'#attached' => ['library' => ['test/parent']],
'#title' => 'Parent',
// Load the element from cache and verify the presence of the #attached
// JavaScript.
- $element = ['#cache' => ['keys' => ['simpletest', 'drupal_render', 'children_attached']]];
+ $element = ['#cache' => ['keys' => ['simpletest', 'renderer', 'children_attached']]];
$this->assertTrue(strlen($this->renderer->renderRoot($element)) > 0, 'The element was retrieved from cache.');
$this->assertEquals($element['#attached']['library'], $expected_libraries, 'The element, child and subchild #attached libraries are included.');
}
$this->cacheFactory->expects($this->atLeastOnce())
->method('get')
->with($bin)
- ->willReturnCallback(function($requested_bin) use ($bin, $custom_cache) {
+ ->willReturnCallback(function ($requested_bin) use ($bin, $custom_cache) {
if ($requested_bin === $bin) {
return $custom_cache;
}
];
$data[] = [$test_element, ['bar', 'foo'], $expected_cache_items];
+ // Ensure that bubbleable metadata has been collected from children and set
+ // correctly to the main level of the render array. That ensures that correct
+ // bubbleable metadata exists if render array gets rendered multiple times.
+ $test_element = [
+ '#cache' => [
+ 'keys' => ['parent'],
+ 'tags' => ['yar', 'har']
+ ],
+ '#markup' => 'parent',
+ 'child' => [
+ '#render_children' => TRUE,
+ 'subchild' => [
+ '#cache' => [
+ 'contexts' => ['foo'],
+ 'tags' => ['fiddle', 'dee'],
+ ],
+ '#attached' => [
+ 'library' => ['foo/bar']
+ ],
+ '#markup' => '',
+ ]
+ ],
+ ];
+ $expected_cache_items = [
+ 'parent:foo' => [
+ '#attached' => ['library' => ['foo/bar']],
+ '#cache' => [
+ 'contexts' => ['foo'],
+ 'tags' => ['dee', 'fiddle', 'har', 'yar'],
+ 'max-age' => Cache::PERMANENT,
+ ],
+ '#markup' => 'parent',
+ ],
+ ];
+ $data[] = [$test_element, ['foo'], $expected_cache_items];
+
return $data;
}
'tags' => ['b'],
],
'grandchild' => [
- '#access_callback' => function() use (&$current_user_role) {
+ '#access_callback' => function () use (&$current_user_role) {
// Only role A cannot access this subtree.
return $current_user_role !== 'A';
},
$data = [];
// Test element without theme.
- $data[] = [[
- 'foo' => [
- '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
- ]]];
+ $data[] = [
+ [
+ 'foo' => [
+ '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
+ ],
+ ],
+ ];
// Test element with theme.
- $data[] = [[
- '#theme' => 'common_test_render_element',
- 'foo' => [
- '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
- ]]];
+ $data[] = [
+ [
+ '#theme' => 'common_test_render_element',
+ 'foo' => [
+ '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
+ ],
+ ],
+ ];
return $data;
}