diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index d67bcad..8cd0e47 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -296,7 +296,7 @@ public function createDerivative($original_uri, $derivative_uri) { } foreach ($this->getEffects() as $effect) { - $effect->applyEffect($image); + $effect->applyEffect($image, $this); } if (!$image->save($derivative_uri)) { diff --git a/core/modules/image/lib/Drupal/image/ImageEffectInterface.php b/core/modules/image/lib/Drupal/image/ImageEffectInterface.php index 66b7f4e..5f675ad 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectInterface.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectInterface.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Core\Image\ImageInterface; +use Drupal\image\Entity\ImageStyle; /** * Defines the interface for image effects. @@ -21,11 +22,13 @@ * * @param \Drupal\Core\Image\ImageInterface $image * An image file object. + * @param \Drupal\image\Entity\ImageStyle $style + * An image style object. * * @return bool * TRUE on success. FALSE if unable to perform the image effect on the image. */ - public function applyEffect(ImageInterface $image); + public function applyEffect(ImageInterface $image, ImageStyle $style); /** * Determines the dimensions of the styled image. diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php index 39f58f3..0e9e355 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; +use Drupal\image\Entity\ImageStyle; /** * Crops an image resource. @@ -25,7 +26,7 @@ class CropImageEffect extends ResizeImageEffect { /** * {@inheritdoc} */ - public function applyEffect(ImageInterface $image) { + public function applyEffect(ImageInterface $image, ImageStyle $style) { list($x, $y) = explode('-', $this->configuration['anchor']); $x = image_filter_keyword($x, $image->getWidth(), $this->configuration['width']); $y = image_filter_keyword($y, $image->getHeight(), $this->configuration['height']); diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/DesaturateImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/DesaturateImageEffect.php index 912bec9..3a426e1 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/DesaturateImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/DesaturateImageEffect.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; +use Drupal\image\Entity\ImageStyle; use Drupal\image\ImageEffectBase; /** @@ -32,7 +33,7 @@ public function transformDimensions(array &$dimensions) { /** * {@inheritdoc} */ - public function applyEffect(ImageInterface $image) { + public function applyEffect(ImageInterface $image, ImageStyle $style) { if (!$image->desaturate()) { watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php index 27d5538..32d8545 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; +use Drupal\image\Entity\ImageStyle; use Drupal\image\ConfigurableImageEffectInterface; use Drupal\image\ImageEffectBase; @@ -27,7 +28,7 @@ class ResizeImageEffect extends ImageEffectBase implements ConfigurableImageEffe /** * {@inheritdoc} */ - public function applyEffect(ImageInterface $image) { + public function applyEffect(ImageInterface $image, ImageStyle $style) { if (!$image->resize($this->configuration['width'], $this->configuration['height'])) { watchdog('image', 'Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php index 571c5fa..247fb74 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; +use Drupal\image\Entity\ImageStyle; use Drupal\image\ConfigurableImageEffectInterface; use Drupal\image\ImageEffectBase; @@ -27,7 +28,7 @@ class RotateImageEffect extends ImageEffectBase implements ConfigurableImageEffe /** * {@inheritdoc} */ - public function applyEffect(ImageInterface $image) { + public function applyEffect(ImageInterface $image, ImageStyle $style) { // Convert short #FFF syntax to full #FFFFFF syntax. if (strlen($this->configuration['bgcolor']) == 4) { $c = $this->configuration['bgcolor']; diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleAndCropImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleAndCropImageEffect.php index 39bd2ec..2a706a7 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleAndCropImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleAndCropImageEffect.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; +use Drupal\image\Entity\ImageStyle; /** * Scales and crops an image resource. @@ -25,7 +26,7 @@ class ScaleAndCropImageEffect extends ResizeImageEffect { /** * {@inheritdoc} */ - public function applyEffect(ImageInterface $image) { + public function applyEffect(ImageInterface $image, ImageStyle $style) { if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) { watchdog('image', 'Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php index 1dae008..ef011a0 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Image; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; +use Drupal\image\Entity\ImageStyle; /** * Scales an image resource. @@ -26,7 +27,7 @@ class ScaleImageEffect extends ResizeImageEffect { /** * {@inheritdoc} */ - public function applyEffect(ImageInterface $image) { + public function applyEffect(ImageInterface $image, ImageStyle $style) { if (!$image->scale($this->configuration['width'], $this->configuration['height'], $this->configuration['upscale'])) { watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php index 8afcb22..7e29b51 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php @@ -29,6 +29,13 @@ class ImageEffectsTest extends ToolkitTestBase { */ protected $manager; + /** + * A dummy image style. + * + * @var \Drupal\image\Entity\ImageStyle + */ + protected $imageStyle; + public static function getInfo() { return array( 'name' => 'Image effects', @@ -40,6 +47,7 @@ public static function getInfo() { public function setUp() { parent::setUp(); $this->manager = $this->container->get('plugin.manager.image.effect'); + $this->imageStyle = entity_create('image_style', array('name' => 'style_foo', 'label' => $this->randomString())); } /** @@ -172,7 +180,7 @@ function testImageEffectsCaching() { */ protected function assertImageEffect($effect_name, array $data) { $effect = $this->manager->createInstance($effect_name, array('data' => $data)); - return $this->assertTrue($effect->applyEffect($this->image), 'Function returned the expected value.'); + return $this->assertTrue($effect->applyEffect($this->image, $this->imageStyle), 'Function returned the expected value.'); } } diff --git a/core/modules/image/tests/modules/image_module_test/lib/Drupal/image_module_test/Plugin/ImageEffect/NullTestImageEffect.php b/core/modules/image/tests/modules/image_module_test/lib/Drupal/image_module_test/Plugin/ImageEffect/NullTestImageEffect.php index 52731fe..23105e4 100644 --- a/core/modules/image/tests/modules/image_module_test/lib/Drupal/image_module_test/Plugin/ImageEffect/NullTestImageEffect.php +++ b/core/modules/image/tests/modules/image_module_test/lib/Drupal/image_module_test/Plugin/ImageEffect/NullTestImageEffect.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; +use Drupal\image\Entity\ImageStyle; use Drupal\image\ImageEffectBase; /** @@ -25,7 +26,7 @@ class NullTestImageEffect extends ImageEffectBase { /** * {@inheritdoc} */ - public function applyEffect(ImageInterface $image) { + public function applyEffect(ImageInterface $image, ImageStyle $style) { return TRUE; }