diff --git a/core/core.services.yml b/core/core.services.yml index 7d0bb62..77aabf2 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -529,7 +529,7 @@ services: arguments: ['@container.namespaces', '@cache.cache', '@language_manager'] image.toolkit.operation.manager: class: Drupal\system\Plugin\ImageToolkitOperationManager - arguments: ['@container.namespaces', '@cache.cache', '@language_manager'] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] image.toolkit: class: Drupal\system\Plugin\ImageToolkitInterface factory_method: getDefaultToolkit diff --git a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php index d296100..5e522fb 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -115,8 +115,6 @@ public function getDefinitions() { // instead of requiring us to work with the annotation object. $definition = $annotation->get(); $definition['class'] = $class; - // Allow ID to be built later. Set an index ID as fallback. - $definition['id'] = isset($definition['id']) ? $definition['id'] : count($definitions); $definitions[$definition['id']] = $definition; } } diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index f7248c2..858e2da 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -107,7 +107,7 @@ public function __construct($source, ImageToolkitInterface $toolkit) { * {@inheritdoc} */ public function isSupported() { - return in_array($this->getType(), $this->toolkit->supportedTypes()); + return in_array($this->getType(), $this->getToolkit()->supportedTypes()); } /** @@ -195,7 +195,7 @@ public function hasResource() { public function getResource() { if (!$this->hasResource()) { $this->processInfo(); - $this->toolkit->load($this); + $this->getToolkit()->load($this); } return $this->resource; } @@ -218,8 +218,8 @@ public function getSource() { /** * {@inheritdoc} */ - public function getToolkitId() { - return $this->toolkit->getPluginId(); + public function getToolkit() { + return $this->toolkit; } /** @@ -229,7 +229,7 @@ public function save($destination = NULL) { if (empty($destination)) { $destination = $this->getSource(); } - if ($return = $this->toolkit->save($this, $destination)) { + if ($return = $this->getToolkit()->save($this, $destination)) { // Clear the cached file size and refresh the image information. clearstatcache(TRUE, $destination); $this->setSource($destination); @@ -247,8 +247,7 @@ public function save($destination = NULL) { * Prepares the image information. * * Drupal supports GIF, JPG and PNG file formats when used with the GD - * toolkit, and may support others, depending on which toolkits are - * installed. + * toolkit, and may support others, depending on which toolkit is active. * * @return bool * FALSE, if the file could not be found or is not an image. Otherwise, the @@ -264,7 +263,7 @@ protected function processInfo() { return FALSE; } - if ($details = $this->toolkit->getInfo($this)) { + if ($details = $this->getToolkit()->getInfo($this)) { $this->height = $details['height']; $this->width = $details['width']; $this->type = $details['type']; @@ -326,7 +325,7 @@ public function crop($x, $y, $width, $height) { $width = (int) round($width); $height = (int) round($height); - return $this->toolkit->process('crop', $this, array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height)); + return $this->getToolkit()->process('crop', $this, array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height)); } /** @@ -336,21 +335,21 @@ public function resize($width, $height) { $width = (int) round($width); $height = (int) round($height); - return $this->toolkit->process('resize', $this, array('width' => $width, 'height' => $height)); + return $this->getToolkit()->process('resize', $this, array('width' => $width, 'height' => $height)); } /** * {@inheritdoc} */ public function desaturate() { - return $this->toolkit->process('desaturate', $this); + return $this->getToolkit()->process('desaturate', $this); } /** * {@inheritdoc} */ public function rotate($degrees, $background = NULL) { - return $this->toolkit->process('rotate', $this, array('degrees' => $degrees, 'background' => $background)); + return $this->getToolkit()->process('rotate', $this, array('degrees' => $degrees, 'background' => $background)); } /** diff --git a/core/lib/Drupal/Core/Image/ImageInterface.php b/core/lib/Drupal/Core/Image/ImageInterface.php index 5966ab2..3efe27e 100644 --- a/core/lib/Drupal/Core/Image/ImageInterface.php +++ b/core/lib/Drupal/Core/Image/ImageInterface.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\Image; +use Drupal\system\Plugin\ImageToolkitInterface; /** * Provides an interface for image objects. @@ -136,12 +137,12 @@ public function setSource($source); public function getSource(); /** - * Returns the ID of the image toolkit used for this image file. + * Returns the image toolkit used for this image file. * - * @return string - * The ID of the image toolkit. + * @return ImageToolkitInterface + * The image toolkit. */ - public function getToolkitId(); + public function getToolkit(); /** * Closes the image and saves the changes to a file. 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..6eacc64 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php @@ -30,7 +30,7 @@ public function applyEffect(ImageInterface $image) { $x = image_filter_keyword($x, $image->getWidth(), $this->configuration['width']); $y = image_filter_keyword($y, $image->getHeight(), $this->configuration['height']); if (!$image->crop($x, $y, $this->configuration['width'], $this->configuration['height'])) { - watchdog('image', 'Image 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); + watchdog('image', 'Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkit()->getPluginId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; } return TRUE; 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..5ce7dd6 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/DesaturateImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/DesaturateImageEffect.php @@ -34,7 +34,7 @@ public function transformDimensions(array &$dimensions) { */ public function applyEffect(ImageInterface $image) { 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); + watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkit()->getPluginId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; } return TRUE; 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..722ffc8 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php @@ -29,7 +29,7 @@ class ResizeImageEffect extends ImageEffectBase implements ConfigurableImageEffe */ public function applyEffect(ImageInterface $image) { 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); + watchdog('image', 'Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkit()->getPluginId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; } return TRUE; @@ -38,15 +38,6 @@ public function applyEffect(ImageInterface $image) { /** * {@inheritdoc} */ - public function transformDimensions(array &$dimensions) { - // The new image will have the exact dimensions defined for the effect. - $dimensions['width'] = $this->configuration['width']; - $dimensions['height'] = $this->configuration['height']; - } - - /** - * {@inheritdoc} - */ public function getSummary() { return array( '#theme' => 'image_resize_summary', @@ -57,6 +48,15 @@ public function getSummary() { /** * {@inheritdoc} */ + public function transformDimensions(array &$dimensions) { + // The new image will have the exact dimensions defined for the effect. + $dimensions['width'] = $this->configuration['width']; + $dimensions['height'] = $this->configuration['height']; + } + + /** + * {@inheritdoc} + */ public function defaultConfiguration() { return array( 'width' => NULL, 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 23c0560..e2aae4b 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php @@ -48,7 +48,7 @@ public function applyEffect(ImageInterface $image) { } if (!$image->rotate($this->configuration['degrees'], $this->configuration['bgcolor'])) { - watchdog('image', 'Image rotate 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); + watchdog('image', 'Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkit()->getPluginId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; } return TRUE; 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..a099879 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleAndCropImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleAndCropImageEffect.php @@ -27,7 +27,7 @@ class ScaleAndCropImageEffect extends ResizeImageEffect { */ public function applyEffect(ImageInterface $image) { 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); + watchdog('image', 'Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkit()->getPluginId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; } return TRUE; 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 87b0dac..98e0507 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php @@ -28,7 +28,7 @@ class ScaleImageEffect extends ResizeImageEffect { */ public function applyEffect(ImageInterface $image) { 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); + watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkit()->getPluginId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; } return TRUE; diff --git a/core/modules/system/lib/Drupal/system/Annotation/ImageToolkitOperation.php b/core/modules/system/lib/Drupal/system/Annotation/ImageToolkitOperation.php index f2b1269..3fae10a 100644 --- a/core/modules/system/lib/Drupal/system/Annotation/ImageToolkitOperation.php +++ b/core/modules/system/lib/Drupal/system/Annotation/ImageToolkitOperation.php @@ -19,6 +19,20 @@ class ImageToolkitOperation extends Plugin { /** + * The plugin ID. + * + * @var string + */ + public $id; + + /** + * The id of the image toolkit plugin for which the operation is implemented. + * + * @var \Drupal\system\Plugin\ImageToolkitInterface + */ + public $toolkit; + + /** * The machine name of the image toolkit operation implemented (e.g. "crop"). * * @var string @@ -48,10 +62,11 @@ class ImageToolkitOperation extends Plugin { public $description; /** - * The id of the image toolkit plugin for which the operation is implemented. + * The weight of the image toolkit operation plugin, used to prioritize + * plugins that implement the same operation for the same toolkit. * - * @var \Drupal\system\Plugin\ImageToolkit + * @var number */ - public $toolkit; + public $weight; } 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 ba1c8b5..4105188 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 @@ -8,24 +8,23 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines GD2 Crop operation. * * @ImageToolkitOperation( + * id = "gd.crop", + * toolkit = "gd", * operation = "crop", * label = @Translation("Crop"), * description = @Translation("GD2 toolkit crop"), - * toolkit = "gd", * weight = 0 * ) */ -class GDCrop extends ImageToolkitOperationBase { +class GDCrop extends PluginBase implements ImageToolkitOperationInterface { /** * Crops an image. @@ -33,8 +32,8 @@ class GDCrop extends ImageToolkitOperationBase { * The image resource, width, and height values will be modified by this * call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit - * An image toolkit. + * @param \Drupal\system\Plugin\ImageToolkit\GDToolkit $toolkit + * A GD image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. * @param array $data 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 61a4968..6802d60 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 @@ -8,24 +8,23 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines GD2 Desaturate operation. * * @ImageToolkitOperation( + * id = "gd.desaturate", + * toolkit = "gd", * operation = "desaturate", * label = @Translation("Desaturate"), * description = @Translation("GD2 toolkit desaturate"), - * toolkit = "gd", * weight = 0 * ) */ -class GDDesaturate extends ImageToolkitOperationBase { +class GDDesaturate extends PluginBase implements ImageToolkitOperationInterface { /** * Converts an image resource to grayscale. @@ -33,7 +32,7 @@ class GDDesaturate extends ImageToolkitOperationBase { * Note that transparent GIFs loose transparency when desaturated. The image * resource value will be modified by this call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * @param \Drupal\system\Plugin\ImageToolkit\GDToolkit $toolkit * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. 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 bd976e3..802be9e 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 @@ -8,24 +8,23 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines GD2 resize operation. * * @ImageToolkitOperation( + * id = "gd.resize", + * toolkit = "gd", * operation = "resize", * label = @Translation("Resize"), * description = @Translation("GD2 toolkit resize"), - * toolkit = "gd", * weight = 0 * ) */ -class GDResize extends ImageToolkitOperationBase { +class GDResize extends PluginBase implements ImageToolkitOperationInterface { /** * Scales an image to the specified size. @@ -33,7 +32,7 @@ class GDResize extends ImageToolkitOperationBase { * The image resource, width, and height values will be modified by this * call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * @param \Drupal\system\Plugin\ImageToolkit\GDToolkit $toolkit * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. 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 47ab5d3..038393e 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 @@ -8,16 +8,16 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines GD2 rotate operation. * * @ImageToolkitOperation( + * id = "gd.rotate", + * toolkit = "gd", * operation = "rotate", * label = @Translation("Rotate"), * description = @Translation("GD2 toolkit rotate"), @@ -25,7 +25,7 @@ * weight = 0 * ) */ -class GDRotate extends ImageToolkitOperationBase { +class GDRotate extends PluginBase implements ImageToolkitOperationInterface { /** * Rotates an image the given number of degrees. @@ -33,7 +33,7 @@ class GDRotate extends ImageToolkitOperationBase { * An image object. The image resource, width, and height values will * be modified by this call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * @param \Drupal\system\Plugin\ImageToolkit\GDToolkit $toolkit * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationManager.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationManager.php index bc49af1..289adf0 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationManager.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationManager.php @@ -8,6 +8,7 @@ namespace Drupal\system\Plugin; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\Discovery\AlterDecorator; @@ -27,19 +28,13 @@ class ImageToolkitOperationManager extends DefaultPluginManager { * Cache backend instance to use. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke the alter hook with. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { parent::__construct('Plugin/ImageToolkit/Operation', $namespaces, 'Drupal\system\Annotation\ImageToolkitOperation'); - // Create valid IDs for plugin definitions. - $definitions = array(); - foreach ($this->discovery->getDefinitions() as $definition) { - $id = $definition['provider'] . '.' . $definition['toolkit'] . '.' . $definition['operation']; - $definition['id'] = $id; - $definitions[$id] = $definition; - } - $this->definitions = $definitions; - + $this->alterInfo($module_handler, 'image_toolkit_operation'); $this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit_operation'); } @@ -53,7 +48,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac * The operation (e.g. "crop"). * * @return string - * A full image toolkit operation plugin ID (e.g. "system.gd.crop"). + * A full image toolkit operation plugin ID (e.g. "system.gd.crop"), or the + * empty string if no suitable plugin could be found. */ public function getToolkitOperationPluginId($toolkit, $operation) { $definitions = array_filter($this->getDefinitions(), function ($definition) use ($toolkit, $operation) { @@ -66,6 +62,7 @@ public function getToolkitOperationPluginId($toolkit, $operation) { $definition = reset($definitions); return $definition['id']; } + return ''; } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php index 5f6c4dc..a24c22c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php @@ -39,7 +39,7 @@ function testGetAvailableToolkits() { function testLoad() { $image = $this->getImage(); $this->assertTrue(is_object($image), 'Returned an object.'); - $this->assertEqual($this->toolkit->getPluginId(), $image->getToolkitId(), 'Image had toolkit set.'); + $this->assertEqual($this->toolkit->getPluginId(), $image->getToolkit()->getPluginId(), 'Image had toolkit set.'); $this->assertToolkitOperationsCalled(array('load', 'get_info')); } 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 db0445f..194b84d 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 @@ -8,24 +8,23 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines Test Crop operation. * * @ImageToolkitOperation( + * id = "test.crop", + * toolkit = "test", * operation = "crop", * label = @Translation("Crop"), * description = @Translation("Test toolkit crop"), - * toolkit = "test", * weight = 0 * ) */ -class TestCrop extends ImageToolkitOperationBase { +class TestCrop extends PluginBase implements ImageToolkitOperationInterface { /** * Crops an image. @@ -33,7 +32,7 @@ class TestCrop extends ImageToolkitOperationBase { * The image resource, width, and height values will be modified by this * call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * @param \Drupal\image_test\Plugin\ImageToolkit\TestToolkit $toolkit * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. 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 a48a28e..ca3630a 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 @@ -8,24 +8,23 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines Test Desaturate operation. * * @ImageToolkitOperation( + * id = "test.desaturate", + * toolkit = "test", * operation = "desaturate", * label = @Translation("Desaturate"), * description = @Translation("Test toolkit desaturate"), - * toolkit = "test", * weight = 0 * ) */ -class TestDesaturate extends ImageToolkitOperationBase { +class TestDesaturate extends PluginBase implements ImageToolkitOperationInterface { /** * Converts an image resource to grayscale. @@ -33,7 +32,7 @@ class TestDesaturate extends ImageToolkitOperationBase { * Note that transparent GIFs loose transparency when desaturated. The image * resource value will be modified by this call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * @param \Drupal\image_test\Plugin\ImageToolkit\TestToolkit $toolkit * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. 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 8353fb6..e96003b 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 @@ -8,24 +8,23 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines Test resize operation. * * @ImageToolkitOperation( + * id = "test.resize", + * toolkit = "test", * operation = "resize", * label = @Translation("Resize"), * description = @Translation("Test toolkit resize"), - * toolkit = "test", * weight = 0 * ) */ -class TestResize extends ImageToolkitOperationBase { +class TestResize extends PluginBase implements ImageToolkitOperationInterface { /** * Scales an image to the specified size. @@ -33,7 +32,7 @@ class TestResize extends ImageToolkitOperationBase { * The image resource, width, and height values will be modified by this * call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * @param \Drupal\image_test\Plugin\ImageToolkit\TestToolkit $toolkit * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. 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 b08476b..8514ca8 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 @@ -8,24 +8,23 @@ namespace Drupal\image_test\Plugin\ImageToolkit\Operation; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; -use Drupal\system\Annotation\ImageToolkitOperation; use Drupal\system\Plugin\ImageToolkitInterface; -use Drupal\system\Plugin\ImageToolkitOperationBase; +use Drupal\system\Plugin\ImageToolkitOperationInterface; /** * Defines Test rotate operation. * * @ImageToolkitOperation( + * id = "test.rotate", + * toolkit = "test", * operation = "rotate", * label = @Translation("Rotate"), * description = @Translation("Test toolkit rotate"), - * toolkit = "test", * weight = 0 * ) */ -class TestRotate extends ImageToolkitOperationBase { +class TestRotate extends PluginBase implements ImageToolkitOperationInterface { /** * Rotates an image the given number of degrees. @@ -33,7 +32,7 @@ class TestRotate extends ImageToolkitOperationBase { * An image object. The image resource, width, and height values will * be modified by this call. * - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * @param \Drupal\image_test\Plugin\ImageToolkit\TestToolkit $toolkit * An image toolkit. * @param \Drupal\Core\Image\ImageInterface $image * An image object. diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index b393d00..27c4d92 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -154,10 +154,10 @@ public function testSetSource() { } /** - * Tests \Drupal\Core\Image\Image::getToolkitId(). + * Tests \Drupal\Core\Image\Image::getToolkit(). */ - public function testGetToolkitId() { - $this->assertEquals($this->image->getToolkitId(), 'gd'); + public function testGetToolkit() { + $this->assertEquals($this->image->getToolkit()->getPluginId(), 'gd'); } /**