diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php index dcda84e..ba08048 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -40,19 +40,36 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi * {@inheritdoc} */ public function prepare(ImageInterface $image, array &$arguments) { + $arguments = $this->prepareArguments($arguments); + } + + /** + * 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. + */ + protected function prepareArguments(array $arguments) { foreach ($this->getPluginDefinition()['arguments'] as $id => $argument) { // The defined argument hasn't been provided. if (!array_key_exists($id, $arguments)) { - if (!empty($argument['required'])) { + if ($argument['required']) { // If the argument is required throw an exception. throw new \InvalidArgumentException("Argument '$id' expected by plugin '" . $this->getPluginId() . "' but not passed."); } else { - // Optional argument? Assign the default value or NULL. - $arguments[$id] = array_key_exists('default', $argument) ? $argument['default'] : NULL; + // Optional argument? Assign the default value. + $arguments[$id] = $argument['default']; } } } + + return $arguments; } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Crop.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Crop.php index e2507de..15c21f7 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Crop.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Crop.php @@ -20,16 +20,16 @@ * 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", + * "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", + * "description" = "The starting y offset at which to start the crop, in pixels" * }, * "width" = { - * "description" = "The width of the cropped area, in pixels", + * "description" = "The width of the cropped area, in pixels" * }, * "height" = { - * "description" = "The height of the cropped area, in pixels", + * "description" = "The height of the cropped area, in pixels" * } * } * ) diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Resize.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Resize.php index 8fc0286..c7ea101 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Resize.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Resize.php @@ -20,10 +20,10 @@ * description = @Translation("Resizes an image to the given dimensions (ignoring aspect ratio)."), * arguments = { * "width" = { - * "description" = "The new width of the resized image, in pixels", + * "description" = "The new width of the resized image, in pixels" * }, * "height" = { - * "description" = "The new height of the resized image, in pixels", + * "description" = "The new height of the resized image, in pixels" * } * } * ) diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Rotate.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Rotate.php index 0b14d40..af238e2 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Rotate.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -20,7 +20,7 @@ * description = @Translation("Rotates an image by the given number of degrees."), * arguments = { * "degrees" = { - * "description" = "The number of (clockwise) degrees to rotate the image", + * "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", diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php index 637ec8c..977ec34 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php @@ -20,10 +20,10 @@ * 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", + * "description" = "The target width, in pixels" * }, * "height" = { - * "description" = "The target height, in pixels", + * "description" = "The target height, in pixels" * } * } * ) diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Crop.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Crop.php index 7406cc5..f41e1ce 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Crop.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Crop.php @@ -20,16 +20,16 @@ * description = @Translation("Test toolkit crop"), * arguments = { * "x" = { - * "description" = "The starting x offset at which to start the crop, in pixels", + * "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", + * "description" = "The starting y offset at which to start the crop, in pixels" * }, * "width" = { - * "description" = "The width of the cropped area, in pixels", + * "description" = "The width of the cropped area, in pixels" * }, * "height" = { - * "description" = "The height of the cropped area, in pixels", + * "description" = "The height of the cropped area, in pixels" * } * } * ) diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Resize.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Resize.php index 85047a0..b4147f3 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Resize.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Resize.php @@ -20,10 +20,10 @@ * description = @Translation("Test toolkit resize"), * arguments = { * "width" = { - * "description" = "The new width of the resized image, in pixels", + * "description" = "The new width of the resized image, in pixels" * }, * "height" = { - * "description" = "The new height of the resized image, in pixels", + * "description" = "The new height of the resized image, in pixels" * } * } * ) diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Rotate.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Rotate.php index 2fc0b09..81a5dd5 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Rotate.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Rotate.php @@ -20,7 +20,7 @@ * description = @Translation("Test toolkit rotate"), * arguments = { * "degrees" = { - * "description" = "The number of (clockwise) degrees to rotate the image", + * "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", diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php index 697835a..7767f73 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/ScaleAndCrop.php @@ -19,10 +19,10 @@ * 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", + * "description" = "The target width, in pixels" * }, * "height" = { - * "description" = "The target height, in pixels", + * "description" = "The target height, in pixels" * } * } * ) diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index 367f7d9..d124026 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -91,7 +91,7 @@ protected function getToolkitMock(array $stubs = array()) { protected function getToolkitOperationMock($class_name) { $mock_builder = $this->getMockBuilder('Drupal\\system\\Plugin\\ImageToolkit\\Operation\\gd\\' . $class_name); return $mock_builder - ->setMethods(array('apply', 'validateArguments')) + ->setMethods(array('apply', 'prepareArguments')) ->disableOriginalConstructor() ->getMock(); } @@ -151,7 +151,7 @@ protected function getTestImageForOperation($class_name) { ->will($this->returnValue($this->toolkitOperation)); $this->toolkitOperation->expects($this->any()) - ->method('validateArguments') + ->method('prepareArguments') ->will($this->returnArgument(0)); $this->image = new Image($this->source, $this->toolkit);