diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 0265d5663e..0a94b6d707 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -223,6 +223,12 @@ function template_preprocess_responsive_image(&$variables) { $variables['img_element']['#title'] = $variables['attributes']['title']; unset($variables['attributes']['title']); } + if (isset($variables['img_element']['#width'])) { + $variables['attributes']['width'] = $variables['img_element']['#width']; + } + if (isset($variables['img_element']['#height'])) { + $variables['attributes']['height'] = $variables['img_element']['#height']; + } $variables['img_element']['#attributes'] = $variables['attributes']; } } diff --git a/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php index c99ee3084a..eed27bca26 100644 --- a/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php @@ -493,7 +493,7 @@ public function testResponsiveImageFieldFormattersMultipleSources() { $image_uri = File::load($node->{$field_name}->target_id)->getFileUri(); $medium_transform_url = $this->fileUrlGenerator->transformRelative($medium_style->buildUrl($image_uri)); $large_transform_url = $this->fileUrlGenerator->transformRelative($large_style->buildUrl($image_uri)); - $this->assertSession()->responseMatches('/\w+/'); + $this->assertSession()->responseMatches('/\w+/'); $this->responsiveImgStyle // Test the output of an empty media query. @@ -505,7 +505,7 @@ public function testResponsiveImageFieldFormattersMultipleSources() { // Assert the picture tag has source tags that include dimensions. $this->drupalGet('node/' . $nid); - $this->assertSession()->responseMatches('/\s+\s+\s+\w+\s+<\/picture>/'); + $this->assertSession()->responseMatches('/\s+\s+\s+\w+\s+<\/picture>/'); } /**