diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 27c83ca..c383d4d 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -162,6 +162,7 @@ function theme_responsive_image_formatter($variables) { * - alt: The alternative text for text-based browsers. * - title: The title text is displayed when the image is hovered in some * popular browsers. + * - attributes: Associative array of attributes to be placed in the img tag. * - style_name: The name of the style to be used as a fallback image. * - mapping_id: The ID of the responsive image mapping. * @@ -186,7 +187,7 @@ function template_preprocess_responsive_image(&$variables) { // unnecessary preloading of images in older browsers. See // http://scottjehl.github.io/picturefill/#using-picture and // http://scottjehl.github.io/picturefill/#gotchas for more information. - $variables['fallback_image'] = array( + $variables['img_element'] = array( '#theme' => 'image', '#srcset' => array( array( @@ -196,7 +197,8 @@ function template_preprocess_responsive_image(&$variables) { ); foreach (array('alt', 'title', 'attributes') as $key) { if (isset($variables[$key])) { - $variables['fallback_image']["#$key"] = $variables[$key]; + $variables['img_element']["#$key"] = $variables[$key]; + unset($variables[$key]); } } } @@ -380,13 +382,17 @@ function responsive_image_build_source_attributes(ImageInterface $image, $variab } } ksort($srcset); - $sources[] = new \Drupal\Core\Template\Attribute(array( + $source_attributes = new \Drupal\Core\Template\Attribute(array( 'srcset' => implode(', ', array_unique($srcset)), 'media' => $breakpoint->getMediaQuery(), - // Only set a MIME type if it's the same for all derivative images. - 'type' => count(array_unique($derivative_mime_types)) == 1 ? $derivative_mime_types[0] : '', - 'sizes' => implode(',', array_unique($sizes)), )); + if (count(array_unique($derivative_mime_types)) == 1) { + $source_attributes->setAttribute('type', $derivative_mime_types[0]); + } + if (!empty($sizes)) { + $source_attributes->setAttribute('sizes', implode(',', array_unique($sizes))); + } + $sources[] = $source_attributes; } } return $sources; diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldUITest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldUiTest.php similarity index 98% rename from core/modules/responsive_image/src/Tests/ResponsiveImageFieldUITest.php rename to core/modules/responsive_image/src/Tests/ResponsiveImageFieldUiTest.php index 57e2bff..76ef6b6 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldUITest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldUiTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\responsive_image\Tests\ResponsiveImageFieldUITest. + * Contains \Drupal\responsive_image\Tests\ResponsiveImageFieldUiTest. */ namespace Drupal\responsive_image\Tests; @@ -16,7 +16,7 @@ * * @group responsive_image */ -class ResponsiveImageFieldUITest extends WebTestBase { +class ResponsiveImageFieldUiTest extends WebTestBase { use FieldUiTestTrait; diff --git a/core/modules/responsive_image/templates/responsive-image.html.twig b/core/modules/responsive_image/templates/responsive-image.html.twig index 12501e0..7e6099c 100644 --- a/core/modules/responsive_image/templates/responsive-image.html.twig +++ b/core/modules/responsive_image/templates/responsive-image.html.twig @@ -4,7 +4,6 @@ * Default theme implementation of a responsive image. * * Available variables: - * - attributes: HTML attributes for the tag. * - sources: The attributes of the tags for this tag. * - fallback_image: The fallback tag to use for this tag. * @@ -14,7 +13,7 @@ * @ingroup themeable */ #} - + {% if sources %} {# Internet Explorer 9 doesn't recognise source elements that are wrapped in @@ -26,5 +25,5 @@ {% endfor %} {% endif %} - {{ fallback_image }} + {{ img_element }}