diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php index eaa74f1..0acd4d6 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php @@ -21,8 +21,8 @@ public function apply($operation, ImageInterface $image, array $data = array()) { $manager = \Drupal::service('image.toolkit.operation.manager'); $plugin_id = $manager->getToolkitOperationPluginId($this->getPluginId(), $operation); - $plugin = $manager->createInstance($plugin_id); - return $plugin->apply($this, $image, $data); + $plugin = $manager->createInstance($plugin_id, array(), $this); + return $plugin->apply($image, $data); } } diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php new file mode 100644 index 0000000..231b918 --- /dev/null +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -0,0 +1,38 @@ +toolkit = $toolkit; + } + +} diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php index c212b43..bcda387 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php @@ -21,8 +21,6 @@ /** * Applies a toolkit specific operation to an image. * - * @param \Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit - * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. * @param array $data @@ -32,6 +30,6 @@ * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()); + public function apply(ImageInterface $image, array $data = array()); } diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php index f2976b3..62e317d 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; +use Drupal\Component\Plugin\Factory\DefaultFactory; /** * Manages toolkit operation plugins. @@ -55,4 +56,13 @@ public function getToolkitOperationPluginId($toolkit, $operation) { return "$toolkit.$operation"; } + /** + * {@inheritdoc} + */ + public function createInstance($plugin_id, array $configuration = array(), ImageToolkitInterface $toolkit = NULL) { + $plugin_definition = $this->getDefinition($plugin_id); + $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition); + return new $plugin_class($configuration, $plugin_id, $plugin_definition, $toolkit); + } + } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php index ba88eb8..0ebf982 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php @@ -7,10 +7,8 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines GD2 Crop operation. @@ -23,13 +21,13 @@ * description = @Translation("Crops an image to a rectangle specified by the given dimensions.") * ) */ -class GDCrop extends PluginBase implements ImageToolkitOperationInterface { +class GDCrop extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { - $res = $toolkit->createTmp($image, $data['width'], $data['height']); + public function apply(ImageInterface $image, array $data = array()) { + $res = $this->toolkit->createTmp($image, $data['width'], $data['height']); if (!imagecopyresampled($res, $image->getResource(), 0, 0, $data['x'], $data['y'], $data['width'], $data['height'], $data['width'], $data['height'])) { return FALSE; diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php index 652c53e..1b00f73 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php @@ -7,10 +7,8 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines GD2 Desaturate operation. @@ -23,12 +21,12 @@ * description = @Translation("Converts an image to grayscale.") * ) */ -class GDDesaturate extends PluginBase implements ImageToolkitOperationInterface { +class GDDesaturate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageInterface $image, array $data = array()) { // PHP installations using non-bundled GD do not have imagefilter. if (!function_exists('imagefilter')) { watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $image->getSource())); diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php index e4b4bb7..86a1f6c 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php @@ -7,10 +7,8 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines GD2 resize operation. @@ -23,13 +21,13 @@ * description = @Translation("Resizes an image to the given dimensions (ignoring aspect ratio).") * ) */ -class GDResize extends PluginBase implements ImageToolkitOperationInterface { +class GDResize extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { - $res = $toolkit->createTmp($image, $data['width'], $data['height']); + public function apply(ImageInterface $image, array $data = array()) { + $res = $this->toolkit->createTmp($image, $data['width'], $data['height']); if (!imagecopyresampled($res, $image->getResource(), 0, 0, 0, 0, $data['width'], $data['height'], $image->getWidth(), $image->getHeight())) { return FALSE; diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php index bb962c7..cb32d13 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php @@ -7,10 +7,8 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines GD2 rotate operation. @@ -23,12 +21,12 @@ * description = @Translation("Rotates an image by the given number of degrees.") * ) */ -class GDRotate extends PluginBase implements ImageToolkitOperationInterface { +class GDRotate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageInterface $image, array $data = array()) { // Ensure background variable is set. $data['background'] = isset($data['background']) ? $data['background'] : NULL; diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScale.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScale.php index b135996..415b5bb 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScale.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScale.php @@ -8,7 +8,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; use Drupal\Component\Utility\Image as ImageUtility; /** @@ -27,7 +26,7 @@ class GDScale extends GDResize { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageInterface $image, array $data = array()) { // @todo Dimensions computation will be moved into a dedicated functionality // in https://drupal.org/node/2108307. $data += array('width' => NULL, 'height' => NULL, 'upscale' => FALSE); @@ -42,7 +41,7 @@ public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, arr $data['width'] = $dimensions['width']; $data['height'] = $dimensions['height']; - return parent::apply($toolkit, $image, $data); + return parent::apply($image, $data); } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScaleAndCrop.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScaleAndCrop.php index fcfbb07..9a7096c 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScaleAndCrop.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDScaleAndCrop.php @@ -26,7 +26,7 @@ class GDScaleAndCrop extends GDCrop { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageInterface $image, array $data = array()) { // @todo Dimensions computation will be moved into a dedicated functionality // in https://drupal.org/node/2108307. $width = $image->getWidth(); @@ -37,8 +37,8 @@ public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, arr $width *= $scale; $height *= $scale; - if ($toolkit->apply('resize', $image, array('width' => $width, 'height' => $height))) { - return parent::apply($toolkit, $image, $data); + if ($this->toolkit->apply('resize', $image, array('width' => $width, 'height' => $height))) { + return parent::apply($image, $data); } } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php index f28d205..e1af3b7 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php @@ -7,10 +7,8 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines Test Crop operation. @@ -20,17 +18,16 @@ * toolkit = "test", * operation = "crop", * label = @Translation("Crop"), - * description = @Translation("Test toolkit crop"), - * weight = 0 + * description = @Translation("Test toolkit crop") * ) */ -class TestCrop extends PluginBase implements ImageToolkitOperationInterface { +class TestCrop extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { - $toolkit->logCall('crop', array($image, $data['x'], $data['y'], $data['width'], $data['height'])); + public function apply(ImageInterface $image, array $data = array()) { + $this->toolkit->logCall('crop', array($image, $data['x'], $data['y'], $data['width'], $data['height'])); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php index 9768fce..109a4f6 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php @@ -7,10 +7,8 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines Test Desaturate operation. @@ -20,17 +18,16 @@ * toolkit = "test", * operation = "desaturate", * label = @Translation("Desaturate"), - * description = @Translation("Test toolkit desaturate"), - * weight = 0 + * description = @Translation("Test toolkit desaturate") * ) */ -class TestDesaturate extends PluginBase implements ImageToolkitOperationInterface { +class TestDesaturate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { - $toolkit->logCall('desaturate', array($image)); + public function apply(ImageInterface $image, array $data = array()) { + $this->toolkit->logCall('desaturate', array($image)); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php index 20afb29..e7bed43 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php @@ -7,10 +7,8 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines Test resize operation. @@ -20,17 +18,16 @@ * toolkit = "test", * operation = "resize", * label = @Translation("Resize"), - * description = @Translation("Test toolkit resize"), - * weight = 0 + * description = @Translation("Test toolkit resize") * ) */ -class TestResize extends PluginBase implements ImageToolkitOperationInterface { +class TestResize extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { - $toolkit->logCall('resize', array($image, $data['width'], $data['height'])); + public function apply(ImageInterface $image, array $data = array()) { + $this->toolkit->logCall('resize', array($image, $data['width'], $data['height'])); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php index 405813d..2af823b 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php @@ -7,10 +7,8 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; -use Drupal\Core\ImageToolkit\ImageToolkitOperationInterface; +use Drupal\Core\ImageToolkit\ImageToolkitOperationBase; /** * Defines Test rotate operation. @@ -20,19 +18,18 @@ * toolkit = "test", * operation = "rotate", * label = @Translation("Rotate"), - * description = @Translation("Test toolkit rotate"), - * weight = 0 + * description = @Translation("Test toolkit rotate") * ) */ -class TestRotate extends PluginBase implements ImageToolkitOperationInterface { +class TestRotate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageInterface $image, array $data = array()) { // Ensure background variable is set. $data['background'] = isset($data['background']) ? $data['background'] : NULL; - $toolkit->logCall('rotate', array($image, $data['degrees'], $data['background'])); + $this->toolkit->logCall('rotate', array($image, $data['degrees'], $data['background'])); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScale.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScale.php index 32f6fca..ab5c3ac 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScale.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScale.php @@ -8,7 +8,6 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; /** * Defines Test Scale operation. @@ -26,9 +25,9 @@ class TestScale extends TestResize { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageInterface $image, array $data = array()) { $data += array('width' => NULL, 'height' => NULL, 'upscale' => FALSE); - $toolkit->logCall('scale', array($image, $data['width'], $data['height'], $data['upscale'])); + $this->toolkit->logCall('scale', array($image, $data['width'], $data['height'], $data['upscale'])); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScaleAndCrop.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScaleAndCrop.php index e3c5bc4..2a7885a 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScaleAndCrop.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestScaleAndCrop.php @@ -8,7 +8,6 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; /** * Defines Test Scale and Crop operation. @@ -26,8 +25,8 @@ class TestScaleAndCrop extends TestCrop { /** * {@inheritdoc} */ - public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { - $toolkit->logCall('scale_and_crop', array($image, $data['width'], $data['height'])); + public function apply(ImageInterface $image, array $data = array()) { + $this->toolkit->logCall('scale_and_crop', array($image, $data['width'], $data['height'])); return TRUE; }