summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2015-10-05 06:06:07 (GMT)
committerwebchick2015-10-05 06:06:07 (GMT)
commitb332f08e6a3cbcef8ece57af97e2ac69e749018a (patch)
treee59b08e669dc8580b7c8013fe9c54d0613aad038
parent932f2f2c9d8be5fa4cfe7d84047e7d8402f03fd5 (diff)
Issue #2534066 by Jelle_S, Dom., attiks: Allow selecting the original image when creating a responsive image style
-rw-r--r--core/modules/responsive_image/responsive_image.module8
-rw-r--r--core/modules/responsive_image/src/ResponsiveImageStyleForm.php1
-rw-r--r--core/modules/responsive_image/src/Tests/ResponsiveImageAdminUITest.php18
-rw-r--r--core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php7
-rw-r--r--core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php10
5 files changed, 40 insertions, 4 deletions
diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module
index e4a0c9f..8060498 100644
--- a/core/modules/responsive_image/responsive_image.module
+++ b/core/modules/responsive_image/responsive_image.module
@@ -18,6 +18,7 @@ use Drupal\breakpoint\BreakpointInterface;
* 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 0d03835..c220dbc 100644
--- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
+++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
@@ -84,6 +84,7 @@ class ResponsiveImageStyleForm extends EntityForm {
);
$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 f3106f6..ceac99b 100644
--- a/core/modules/responsive_image/src/Tests/ResponsiveImageAdminUITest.php
+++ b/core/modules/responsive_image/src/Tests/ResponsiveImageAdminUITest.php
@@ -77,7 +77,10 @@ class ResponsiveImageAdminUITest extends WebTestBase {
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 @@ class ResponsiveImageAdminUITest extends WebTestBase {
$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 112caeb..b42831b 100644
--- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
+++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
@@ -148,6 +148,11 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
'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 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
// 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 71e81ed..c916756 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 @@ class ResponsiveImageStyleConfigEntityUnitTest extends UnitTestCase {
'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 @@ class ResponsiveImageStyleConfigEntityUnitTest extends UnitTestCase {
'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());