diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index e4a0c9f396e1c01ae9f0e0dd4874db3fc1332743..80604989666f82433ecaed4ed09ad6b3b1fbb258 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -18,6 +18,7 @@ * The machine name for the empty image breakpoint image style option. */ const RESPONSIVE_IMAGE_EMPTY_IMAGE = '_empty image_'; +const RESPONSIVE_IMAGE_ORIGINAL_IMAGE = '_original image_'; /** * Implements hook_help(). @@ -476,7 +477,12 @@ function responsive_image_get_mime_type($image_style_name, $extension) { } // The MIME type guesser needs a full path, not just an extension, but the // file doesn't have to exist. - $fake_path = 'responsive_image.' . ImageStyle::load($image_style_name)->getDerivativeExtension($extension); + if ($image_style_name === RESPONSIVE_IMAGE_ORIGINAL_IMAGE) { + $fake_path = 'responsive_image.' . $extension; + } + else { + $fake_path = 'responsive_image.' . ImageStyle::load($image_style_name)->getDerivativeExtension($extension); + } return Drupal::service('file.mime_type.guesser.extension')->guess($fake_path); } diff --git a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php index 0d03835e83e5264cf0ef0893e7a3e13644b03adc..c220dbc2d36371a13f9a527f5f4655285c12d82b 100644 --- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php @@ -84,6 +84,7 @@ public function form(array $form, FormStateInterface $form_state) { ); $image_styles = image_style_options(TRUE); + $image_styles[RESPONSIVE_IMAGE_ORIGINAL_IMAGE] = $this->t('- None (original image) -'); $image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = $this->t('- empty image -'); if ((bool) $responsive_image_style->id() && $this->operation != 'duplicate') { diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageAdminUITest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageAdminUITest.php index f3106f6c38f6e609c2df1631938927f6d361f798..ceac99bd671722246198fb9b3ebf4bfa8d9c3df4 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageAdminUITest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageAdminUITest.php @@ -77,7 +77,10 @@ public function testResponsiveImageAdmin() { array('wide', '1x'), array('wide', '2x'), ); - + $image_styles = array_merge( + [RESPONSIVE_IMAGE_EMPTY_IMAGE, RESPONSIVE_IMAGE_ORIGINAL_IMAGE], + array_keys(image_style_options(FALSE)) + ); foreach ($cases as $case) { // Check if the radio buttons are present. $this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_mapping_type]', ''); @@ -85,8 +88,17 @@ public function testResponsiveImageAdmin() { $this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_style]', ''); // Check if the sizes textfields are present. $this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][sizes]', ''); - // Check if the image styles checkboxes are present. - foreach (array_keys(image_style_options(FALSE)) as $image_style_name) { + + foreach ($image_styles as $image_style_name) { + // Check if the image styles are available in the dropdowns. + $this->assertTrue($this->xpath( + '//select[@name=:name]//option[@value=:style]', + [ + ':name' => 'keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_style]', + ':style' => $image_style_name, + ] + )); + // Check if the image styles checkboxes are present. $this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][sizes_image_styles][' . $image_style_name . ']'); } } diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index 112caebec65aba59ebe03f2b0577aad61bf5eefa..b42831b50aa4418de8962adb074149a6a35b17a1 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -148,6 +148,11 @@ protected function addTestImageStyleMappings($empty_styles = FALSE) { 'image_mapping_type' => 'image_style', 'image_mapping' => 'large', )) + // Test the output of the original image. + ->addImageStyleMapping('responsive_image_test_module.wide', '3x', array( + 'image_mapping_type' => 'image_style', + 'image_mapping' => RESPONSIVE_IMAGE_ORIGINAL_IMAGE, + )) ->save(); } } @@ -286,6 +291,8 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles = // Assert the output of the 'srcset' attribute (small multipliers first). $this->assertRaw('data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== 1x, ' . $thumbnail_style->buildUrl($image_uri) . ' 1.5x'); $this->assertRaw('/styles/medium/'); + // Assert the output of the original image. + $this->assertRaw(file_create_url($image_uri) . ' 3x'); // Assert the output of the breakpoints. $this->assertRaw('media="(min-width: 0px)"'); $this->assertRaw('media="(min-width: 560px)"'); diff --git a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php index 71e81edcec0eab545459c553889dd9907b4486b6..c9167565b1d59a4646ee04dc95f73f7830a15933 100644 --- a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php +++ b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php @@ -208,6 +208,10 @@ public function testGetKeyedImageStyleMappings() { 'image_mapping_type' => 'image_style', 'image_mapping' => 'thumbnail', )); + $entity->addImageStyleMapping('test_breakpoint2', '2x', array( + 'image_mapping_type' => 'image_style', + 'image_mapping' => '_original image_', + )); $expected = array( 'test_breakpoint' => array( @@ -236,6 +240,12 @@ public function testGetKeyedImageStyleMappings() { 'image_mapping_type' => 'image_style', 'image_mapping' => 'thumbnail', ), + '2x' => array( + 'breakpoint_id' => 'test_breakpoint2', + 'multiplier' => '2x', + 'image_mapping_type' => 'image_style', + 'image_mapping' => '_original image_', + ), ) ); $this->assertEquals($expected, $entity->getKeyedImageStyleMappings());