diff --git a/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php b/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php index 29d1070..bd5250d 100644 --- a/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php +++ b/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php @@ -56,22 +56,4 @@ class ImageToolkitOperation extends Plugin { */ public $description; - /** - * An array of arguments to be passed to the image toolkit operation. - * - * Keys are the names of the arguments (e.g. "width", "degrees") and each - * value is an associative array having the following keys: - * - description: A string with the argument description. This is used only - * internally for documentation purposes, so it does not need to be - * translatable. - * - required: (optional) A boolean indicating if this argument should be - * provided or not. Defaults to TRUE. - * - default: (optional) When the argument is set to "required" = FALSE, - * this must be set to a default value. Ignored for "required" = TRUE - * arguments. - * - * @var array - */ - public $arguments; - } diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php index 50f38d7..1b34a71 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -39,25 +39,17 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi /** * {@inheritdoc} */ - public function prepare(ImageInterface $image, array &$arguments) { - $arguments = $this->prepareArguments($arguments); - return TRUE; + public function defaultConfiguration() { + return array(); } /** - * Normalizes image toolkit operation arguments. - * - * @param array $arguments - * An associative array of arguments to be used by the toolkit operation. - * - * @return array - * An associative array of normalized arguments. - * - * @throws \InvalidArgumentException. + * {@inheritdoc} */ - protected function prepareArguments(array $arguments) { - foreach ($this->getPluginDefinition()['arguments'] as $id => $argument) { - // The defined argument hasn't been provided. + public function prepare(ImageInterface $image, array &$arguments) { + foreach ($this->defaultConfiguration() as $id => $argument) { + $argument += array('required' => TRUE); + // Check if the defined argument has been provided. if (!array_key_exists($id, $arguments)) { if ($argument['required']) { // If the argument is required throw an exception. @@ -65,12 +57,15 @@ protected function prepareArguments(array $arguments) { } else { // Optional argument? Assign the default value. + if (!array_key_exists('default', $argument)) { + // If the default is missing throw an exception. + throw new \InvalidArgumentException("Default for argument '$id' expected by plugin '" . $this->getPluginId() . "' not defined."); + } $arguments[$id] = $argument['default']; } } } - - return $arguments; + return TRUE; } } diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php index 9b0cacb..5f864d0 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php @@ -20,6 +20,25 @@ interface ImageToolkitOperationInterface extends PluginInspectionInterface { /** + * Returns the default configuration of the operation arguments. + * + * An array whose keys are the names of the arguments (e.g. "width", + * "degrees") and each value is an associative array having the following + * keys: + * - description: A string with the argument description. This is used only + * internally for documentation purposes, so it does not need to be + * translatable. + * - required: (optional) A boolean indicating if this argument should be + * provided or not. Defaults to TRUE. + * - default: (optional) When the argument is set to "required" = FALSE, + * this must be set to a default value. Ignored for "required" = TRUE + * arguments. + * + * @return array + */ + public function defaultConfiguration(); + + /** * Validates, normalizes and adds defaults to arguments before sending them * to the apply method. * diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php index 9f5f8f3..15c0487 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php @@ -48,17 +48,6 @@ public function processDefinition(&$definition, $plugin_id) { // plugin is placed under Plugin\ImageToolkit\{plugin_id}. $path = explode('\\', $definition['class']); $definition['toolkit'] = $path[count($path) - 2]; - - foreach ($definition['arguments'] as $id => &$argument) { - // Set argument 'required' as TRUE if hasn't been specified in annotation. - $argument['required'] = isset($argument['required']) ? $argument['required'] : TRUE; - - // If the argument is optional a 'default' should be provided. - if (!$argument['required'] && !array_key_exists('default', $argument)) { - $message = String::format("Argument '@arg' in plugin '@plugin' is optional but doesn't provide a default value.", array('@arg' => $id, '@plugin' => $definition['id'])); - throw new InvalidPluginDefinitionException($message); - } - } } /** diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php index 53f94a6..86128b9 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php @@ -17,21 +17,7 @@ * id = "gd.crop", * operation = "crop", * label = @Translation("Crop"), - * description = @Translation("Crops an image to a rectangle specified by the given dimensions."), - * arguments = { - * "x" = { - * "description" = "The starting x offset at which to start the crop, in pixels" - * }, - * "y" = { - * "description" = "The starting y offset at which to start the crop, in pixels" - * }, - * "width" = { - * "description" = "The width of the cropped area, in pixels" - * }, - * "height" = { - * "description" = "The height of the cropped area, in pixels" - * } - * } + * description = @Translation("Crops an image to a rectangle specified by the given dimensions.") * ) */ class Crop extends ImageToolkitOperationBase { @@ -39,6 +25,30 @@ class Crop extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'x' => array( + 'description' => 'The starting x offset at which to start the crop, in pixels', + ), + 'y' => array( + 'description' => 'The starting y offset at which to start the crop, in pixels', + ), + 'width' => array( + 'description' => 'The width of the cropped area, in pixels', + 'required' => FALSE, + 'default' => NULL, + ), + 'height' => array( + 'description' => 'The height of the cropped area, in pixels', + 'required' => FALSE, + 'default' => NULL, + ), + ); + } + + /** + * {@inheritdoc} + */ public function prepare(ImageInterface $image, array &$arguments) { parent::prepare($image, $arguments); diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php index 908946f..e2312ed 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php @@ -17,8 +17,7 @@ * id = "gd.desaturate", * operation = "desaturate", * label = @Translation("Desaturate"), - * description = @Translation("Converts an image to grayscale."), - * arguments = { } + * description = @Translation("Converts an image to grayscale.") * ) */ class Desaturate extends ImageToolkitOperationBase { @@ -26,6 +25,13 @@ class Desaturate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array(); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { // PHP installations using non-bundled GD do not have imagefilter. if (!function_exists('imagefilter')) { diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php index a6c2e75..8b734f5 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php @@ -17,15 +17,7 @@ * id = "gd.resize", * operation = "resize", * label = @Translation("Resize"), - * description = @Translation("Resizes an image to the given dimensions (ignoring aspect ratio)."), - * arguments = { - * "width" = { - * "description" = "The new width of the resized image, in pixels" - * }, - * "height" = { - * "description" = "The new height of the resized image, in pixels" - * } - * } + * description = @Translation("Resizes an image to the given dimensions (ignoring aspect ratio).") * ) */ class Resize extends ImageToolkitOperationBase { @@ -33,6 +25,20 @@ class Resize extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'width' => array( + 'description' => 'The new width of the resized image, in pixels', + ), + 'height' => array( + 'description' => 'The new height of the resized image, in pixels', + ), + ); + } + + /** + * {@inheritdoc} + */ public function prepare(ImageInterface $image, array &$arguments) { parent::prepare($image, $arguments); diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php index 16a6f78..6e0bf0d 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -17,17 +17,7 @@ * id = "gd.rotate", * operation = "rotate", * label = @Translation("Rotate"), - * description = @Translation("Rotates an image by the given number of degrees."), - * arguments = { - * "degrees" = { - * "description" = "The number of (clockwise) degrees to rotate the image" - * }, - * "background" = { - * "description" = "An hexadecimal integer specifying the background color to use for the uncovered area of the image after the rotation. E.g. 0x000000 for black, 0xff00ff for magenta, and 0xffffff for white. For images that support transparency, this will default to transparent. Otherwise it will be white", - * "required" = FALSE, - * "default" = NULL - * } - * } + * description = @Translation("Rotates an image by the given number of degrees.") * ) */ class Rotate extends ImageToolkitOperationBase { @@ -35,6 +25,22 @@ class Rotate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'degrees' => array( + 'description' => 'The number of (clockwise) degrees to rotate the image', + ), + 'background' => array( + 'description' => 'An hexadecimal integer specifying the background color to use for the uncovered area of the image after the rotation. E.g. 0x000000 for black, 0xff00ff for magenta, and 0xffffff for white. For images that support transparency, this will default to transparent. Otherwise it will be white', + 'required' => FALSE, + 'default' => NULL, + ), + ); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { // PHP installations using non-bundled GD do not have imagerotate. if (!function_exists('imagerotate')) { diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php index 477247b..4512e63 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php @@ -17,24 +17,7 @@ * id = "gd.scale", * operation = "scale", * label = @Translation("Scale"), - * description = @Translation("Scales an image while maintaining aspect ratio. The resulting image can be smaller for one or both target dimensions."), - * arguments = { - * "width" = { - * "description" = "The target width, in pixels. This value is omitted then the scaling will based only on the height value", - * "required" = FALSE, - * "default" = NULL - * }, - * "height" = { - * "description" = "The target height, in pixels. This value is omitted then the scaling will based only on the width value", - * "required" = FALSE, - * "default" = NULL - * }, - * "upscale" = { - * "description" = "Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image", - * "required" = FALSE, - * "default" = FALSE - * } - * } + * description = @Translation("Scales an image while maintaining aspect ratio. The resulting image can be smaller for one or both target dimensions.") * ) */ class Scale extends Resize { @@ -42,6 +25,29 @@ class Scale extends Resize { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'width' => array( + 'description' => 'The target width, in pixels. This value is omitted then the scaling will based only on the height value', + 'required' => FALSE, + 'default' => NULL, + ), + 'height' => array( + 'description' => 'The target height, in pixels. This value is omitted then the scaling will based only on the width value', + 'required' => FALSE, + 'default' => NULL, + ), + 'upscale' => array( + 'description' => 'Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image', + 'required' => FALSE, + 'default' => FALSE, + ), + ); + } + + /** + * {@inheritdoc} + */ public function prepare(ImageInterface $image, array &$arguments) { $width = &$arguments['width']; $height = &$arguments['height']; diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php index 4214d8d..1da80b9 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php @@ -17,15 +17,7 @@ * id = "gd.scale_and_crop", * operation = "scale_and_crop", * label = @Translation("Scale and crop"), - * description = @Translation("Scales an image to the exact width and height given. This plugin achieves the target aspect ratio by cropping the original image equally on both sides, or equally on the top and bottom. This function is useful to create uniform sized avatars from larger images."), - * arguments = { - * "width" = { - * "description" = "The target width, in pixels" - * }, - * "height" = { - * "description" = "The target height, in pixels" - * } - * } + * description = @Translation("Scales an image to the exact width and height given. This plugin achieves the target aspect ratio by cropping the original image equally on both sides, or equally on the top and bottom. This function is useful to create uniform sized avatars from larger images.") * ) */ class ScaleAndCrop extends ImageToolkitOperationBase { @@ -33,6 +25,20 @@ class ScaleAndCrop extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'width' => array( + 'description' => 'The target width, in pixels', + ), + 'height' => array( + 'description' => 'The target height, in pixels', + ), + ); + } + + /** + * {@inheritdoc} + */ public function prepare(ImageInterface $image, array &$arguments) { parent::prepare($image, $arguments); diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Crop.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Crop.php index f41e1ce..ab38c10 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Crop.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Crop.php @@ -17,21 +17,7 @@ * id = "test.crop", * operation = "crop", * label = @Translation("Crop"), - * description = @Translation("Test toolkit crop"), - * arguments = { - * "x" = { - * "description" = "The starting x offset at which to start the crop, in pixels" - * }, - * "y" = { - * "description" = "The starting y offset at which to start the crop, in pixels" - * }, - * "width" = { - * "description" = "The width of the cropped area, in pixels" - * }, - * "height" = { - * "description" = "The height of the cropped area, in pixels" - * } - * } + * description = @Translation("Test toolkit crop") * ) */ class Crop extends ImageToolkitOperationBase { @@ -39,6 +25,30 @@ class Crop extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'x' => array( + 'description' => 'The starting x offset at which to start the crop, in pixels', + ), + 'y' => array( + 'description' => 'The starting y offset at which to start the crop, in pixels', + ), + 'width' => array( + 'description' => 'The width of the cropped area, in pixels', + 'required' => FALSE, + 'default' => NULL, + ), + 'height' => array( + 'description' => 'The height of the cropped area, in pixels', + 'required' => FALSE, + 'default' => NULL, + ), + ); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { $this->toolkit->logCall('crop', array($image, $arguments['x'], $arguments['y'], $arguments['width'], $arguments['height'])); return TRUE; diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Desaturate.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Desaturate.php index e101965..5791c4d 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Desaturate.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Desaturate.php @@ -17,8 +17,7 @@ * id = "test.desaturate", * operation = "desaturate", * label = @Translation("Desaturate"), - * description = @Translation("Test toolkit desaturate"), - * arguments = { } + * description = @Translation("Test toolkit desaturate") * ) */ class Desaturate extends ImageToolkitOperationBase { @@ -26,6 +25,13 @@ class Desaturate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array(); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { $this->toolkit->logCall('desaturate', array($image)); return TRUE; diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Resize.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Resize.php index b4147f3..0a1bc3e 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Resize.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Resize.php @@ -17,15 +17,7 @@ * id = "test.resize", * operation = "resize", * label = @Translation("Resize"), - * description = @Translation("Test toolkit resize"), - * arguments = { - * "width" = { - * "description" = "The new width of the resized image, in pixels" - * }, - * "height" = { - * "description" = "The new height of the resized image, in pixels" - * } - * } + * description = @Translation("Test toolkit resize") * ) */ class Resize extends ImageToolkitOperationBase { @@ -33,6 +25,20 @@ class Resize extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'width' => array( + 'description' => 'The new width of the resized image, in pixels', + ), + 'height' => array( + 'description' => 'The new height of the resized image, in pixels', + ), + ); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { $this->toolkit->logCall('resize', array($image, $arguments['width'], $arguments['height'])); return TRUE; diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Rotate.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Rotate.php index 81a5dd5..a367d38 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Rotate.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Rotate.php @@ -17,17 +17,7 @@ * id = "test.rotate", * operation = "rotate", * label = @Translation("Rotate"), - * description = @Translation("Test toolkit rotate"), - * arguments = { - * "degrees" = { - * "description" = "The number of (clockwise) degrees to rotate the image" - * }, - * "background" = { - * "description" = "An hexadecimal integer specifying the background color to use for the uncovered area of the image after the rotation. E.g. 0x000000 for black, 0xff00ff for magenta, and 0xffffff for white. For images that support transparency, this will default to transparent. Otherwise it will be white", - * "required" = FALSE, - * "default" = NULL - * } - * } + * description = @Translation("Test toolkit rotate") * ) */ class Rotate extends ImageToolkitOperationBase { @@ -35,6 +25,22 @@ class Rotate extends ImageToolkitOperationBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'degrees' => array( + 'description' => 'The number of (clockwise) degrees to rotate the image', + ), + 'background' => array( + 'description' => 'An hexadecimal integer specifying the background color to use for the uncovered area of the image after the rotation. E.g. 0x000000 for black, 0xff00ff for magenta, and 0xffffff for white. For images that support transparency, this will default to transparent. Otherwise it will be white', + 'required' => FALSE, + 'default' => NULL, + ), + ); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { $this->toolkit->logCall('rotate', array($image, $arguments['degrees'], $arguments['background'])); return TRUE; diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Scale.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Scale.php index 9096041..2bb77d9 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Scale.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Scale.php @@ -16,24 +16,7 @@ * id = "test.scale", * operation = "scale", * label = @Translation("Scale"), - * description = @Translation("Scales an image while maintaining aspect ratio. The resulting image can be smaller for one or both target dimensions."), - * arguments = { - * "width" = { - * "description" = "The target width, in pixels. This value is omitted then the scaling will based only on the height value", - * "required" = FALSE, - * "default" = NULL - * }, - * "height" = { - * "description" = "The target height, in pixels. This value is omitted then the scaling will based only on the width value", - * "required" = FALSE, - * "default" = NULL - * }, - * "upscale" = { - * "description" = "Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image", - * "required" = FALSE, - * "default" = FALSE - * } - * } + * description = @Translation("Scales an image while maintaining aspect ratio. The resulting image can be smaller for one or both target dimensions.") * ) */ class Scale extends Resize { @@ -41,6 +24,29 @@ class Scale extends Resize { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'width' => array( + 'description' => 'The target width, in pixels. This value is omitted then the scaling will based only on the height value', + 'required' => FALSE, + 'default' => NULL, + ), + 'height' => array( + 'description' => 'The target height, in pixels. This value is omitted then the scaling will based only on the width value', + 'required' => FALSE, + 'default' => NULL, + ), + 'upscale' => array( + 'description' => 'Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image', + 'required' => FALSE, + 'default' => FALSE, + ), + ); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { $this->toolkit->logCall('scale', array($image, $arguments['width'], $arguments['height'], $arguments['upscale'])); return TRUE; diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php index 7767f73..2334b7a 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php @@ -16,15 +16,7 @@ * id = "test.scale_and_crop", * operation = "scale_and_crop", * label = @Translation("Scale and crop"), - * description = @Translation("Scales an image to the exact width and height given. This plugin achieves the target aspect ratio by cropping the original image equally on both sides, or equally on the top and bottom. This function is useful to create uniform sized avatars from larger images."), - * arguments = { - * "width" = { - * "description" = "The target width, in pixels" - * }, - * "height" = { - * "description" = "The target height, in pixels" - * } - * } + * description = @Translation("Scales an image to the exact width and height given. This plugin achieves the target aspect ratio by cropping the original image equally on both sides, or equally on the top and bottom. This function is useful to create uniform sized avatars from larger images.") * ) */ class ScaleAndCrop extends Crop { @@ -32,6 +24,20 @@ class ScaleAndCrop extends Crop { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return array( + 'width' => array( + 'description' => 'The target width, in pixels', + ), + 'height' => array( + 'description' => 'The target height, in pixels', + ), + ); + } + + /** + * {@inheritdoc} + */ public function apply(ImageInterface $image, array $arguments = array()) { $this->toolkit->logCall('scale_and_crop', array($image, $arguments['width'], $arguments['height'])); return TRUE; diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index ada0d5a..49a0159 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -93,7 +93,7 @@ protected function getToolkitMock(array $stubs = array()) { protected function getToolkitOperationMock($class_name, ImageToolkitInterface $toolkit) { $mock_builder = $this->getMockBuilder('Drupal\\system\\Plugin\\ImageToolkit\\Operation\\gd\\' . $class_name); return $mock_builder - ->setMethods(array('apply', 'prepareArguments')) + ->setMethods(array('apply')) ->setConstructorArgs(array(array(), '', array(), $toolkit)) ->getMock(); } @@ -138,10 +138,6 @@ protected function getTestImageForOperation($class_name) { ->method('getToolkitOperation') ->will($this->returnValue($this->toolkitOperation)); - $this->toolkitOperation->expects($this->any()) - ->method('prepareArguments') - ->will($this->returnArgument(0)); - $this->image = new Image($this->toolkit, $this->source); }