From 7c05a8b5db311db727c1d9a65009fa0f629a6548 Mon Sep 17 00:00:00 2001 From: webchick Date: Fri, 6 Feb 2015 09:20:55 -0800 Subject: [PATCH] Issue #2420751 by Wim Leers, mondrake, attiks: ImageEffectBase::transformDimensions() should have a sane default implementation --- core/modules/image/src/ImageEffectBase.php | 4 +++- core/modules/image/src/ImageEffectInterface.php | 9 ++++++--- .../image/src/Plugin/ImageEffect/ConvertImageEffect.php | 6 ------ .../src/Plugin/ImageEffect/DesaturateImageEffect.php | 6 ------ core/modules/image/src/Tests/ImageDimensionsTest.php | 3 +-- .../src/Plugin/ImageEffect/NullTestImageEffect.php | 8 ++++++++ 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/modules/image/src/ImageEffectBase.php b/core/modules/image/src/ImageEffectBase.php index 3b3bbb7d3e..d0ef25615b 100644 --- a/core/modules/image/src/ImageEffectBase.php +++ b/core/modules/image/src/ImageEffectBase.php @@ -71,7 +71,9 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function transformDimensions(array &$dimensions) { - $dimensions['width'] = $dimensions['height'] = NULL; + // Most image effects will not change the dimensions. This base + // implementation represents this behavior. Override this method if your + // image effect does change the dimensions. } /** diff --git a/core/modules/image/src/ImageEffectInterface.php b/core/modules/image/src/ImageEffectInterface.php index 790d7b2e21..7d2c4ca818 100644 --- a/core/modules/image/src/ImageEffectInterface.php +++ b/core/modules/image/src/ImageEffectInterface.php @@ -37,9 +37,12 @@ public function applyEffect(ImageInterface $image); /** * Determines the dimensions of the styled image. * - * @param array $dimensions - * Dimensions to be modified - an array with components width and height, in - * pixels. + * @param array &$dimensions + * Dimensions to be modified - an array with the following keys: + * - width: the width in pixels, or NULL if unknown + * - height: the height in pixels, or NULL if unknown + * When either of the dimensions are NULL, the corresponding HTML attribute + * will be omitted when an image style using this image effect is used. */ public function transformDimensions(array &$dimensions); diff --git a/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php index d88712ccff..8d78514ac3 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php @@ -23,12 +23,6 @@ */ class ConvertImageEffect extends ConfigurableImageEffectBase { - /** - * {@inheritdoc} - */ - public function transformDimensions(array &$dimensions) { - } - /** * {@inheritdoc} */ diff --git a/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php index 97d31d8221..008f6a8ddd 100644 --- a/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php @@ -21,12 +21,6 @@ */ class DesaturateImageEffect extends ImageEffectBase { - /** - * {@inheritdoc} - */ - public function transformDimensions(array &$dimensions) { - } - /** * {@inheritdoc} */ diff --git a/core/modules/image/src/Tests/ImageDimensionsTest.php b/core/modules/image/src/Tests/ImageDimensionsTest.php index 4d6c76b375..2db7e24c59 100644 --- a/core/modules/image/src/Tests/ImageDimensionsTest.php +++ b/core/modules/image/src/Tests/ImageDimensionsTest.php @@ -221,8 +221,7 @@ function testImageDimensions() { $effect_plugin = $style->getEffect($effect_id); $style->deleteImageEffect($effect_plugin); - // Ensure that an effect with no dimensions callback unsets the dimensions. - // This ensures compatibility with 7.0 contrib modules. + // Ensure that an effect can unset dimensions. $effect = array( 'id' => 'image_module_test_null', 'data' => array(), diff --git a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php index 8fd8632338..bcf63ef4cd 100644 --- a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php +++ b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php @@ -20,6 +20,14 @@ */ class NullTestImageEffect extends ImageEffectBase { + /** + * {@inheritdoc} + */ + public function transformDimensions(array &$dimensions) { + // Unset image dimensions. + $dimensions['width'] = $dimensions['height'] = NULL; + } + /** * {@inheritdoc} */ -- GitLab