diff -u b/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php --- b/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -226,12 +226,16 @@ return ''; } - // Avoid making this change for the referenced elements variable because - // it could cause unexpected behaviour with other templating engines than - // Twig. Save the original referenced variable to allow making changes for - // the referenced variable in case explicitly wanted so. - $original_elements = &$elements; + // Remove all elements except the children because the main level has been + // already rendered when the #render_children is set, and therefore they + // shouldn't have any effect on the render children. $new_elements = array_intersect_key($elements, array_flip($children)); + // Create a new variable that references the render array that was passed + // in. This allows the markup and cache information to be attached after + // rendering the new elements array. + $original_elements = &$elements; + // Change $elements to reference $new_elements. This prevents + // unintentional changes to the render array that was passed in. $elements = &$new_elements; } @@ -535,11 +539,12 @@ $elements['#markup'] = Markup::create($prefix . $elements['#children'] . $suffix); - // #attached and #markup values should be always saved to the referenced - // elements variable. + // #cache, #attached and #markup values should be always saved to the + // referenced elements variable to prevent re-rendering. if (isset($original_elements)) { $original_elements['#markup'] = $elements['#markup']; $original_elements['#attached'] = $elements['#attached']; + $original_elements['#cache'] = CacheableMetadata::createFromRenderArray($elements['#cache']); } // We've rendered this element (and its subtree!), now update the context. diff -u b/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php --- b/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -71,10 +71,8 @@ $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1')); - // 128KB. - $small_file = $this->getTestFile('text', 131072); - // 1.2MB. - $large_file = $this->getTestFile('text', 1310720); + $small_file = $this->getTestFile('text', 131072); // 128KB. + $large_file = $this->getTestFile('text', 1310720); // 1.2MB // Test uploading both a large and small file with different increments. $sizes = array( diff -u b/core/modules/image/src/Tests/ImageFieldValidateTest.php b/core/modules/image/src/Tests/ImageFieldValidateTest.php --- b/core/modules/image/src/Tests/ImageFieldValidateTest.php +++ b/core/modules/image/src/Tests/ImageFieldValidateTest.php @@ -8,7 +8,6 @@ * @group image */ class ImageFieldValidateTest extends ImageFieldTestBase { - /** * Test min/max resolution settings. */ @@ -162,14 +161,14 @@ */ public function testAJAXValidationMessage() { $field_name = strtolower($this->randomMachineName()); - $this->createImageField($field_name, 'article'); + $this->createImageField($field_name, 'article', ['cardinality' => -1]); $this->drupalGet('node/add/article'); /** @var \Drupal\file\FileInterface[] $text_files */ $text_files = $this->drupalGetTestFiles('text'); $text_file = reset($text_files); $edit = array( - 'files[' . $field_name . '_0]' => $this->container->get('file_system')->realpath($text_file->uri), + 'files[' . $field_name . '_0][]' => $this->container->get('file_system')->realpath($text_file->uri), 'title[0][value]' => $this->randomMachineName(), ); $this->drupalPostAjaxForm(NULL, $edit, $field_name . '_0_upload_button');