diff --git a/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php b/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php index 0db12e8..e1383cc 100644 --- a/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php +++ b/core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php @@ -64,8 +64,6 @@ class ImageToolkitOperation extends Plugin { * - description: A string with the argument description. This is used only * internally for documentation purposes, so it doesn't need to be * translatable. - * - type: The TypedData plugin id describing the type of data for this - * argument (e.g. "integer", "float", "boolean"). * - required: (optional) A boolean indicating if this argument should be * provided or not. Defaults to TRUE. * - default: (optional) The default value of this argument when the argument diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php index 9b38d80..5b2e913 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -9,8 +9,6 @@ use Drupal\Core\Image\ImageInterface; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\TypedData\DataDefinition; -use Drupal\Component\Utility\String; abstract class ImageToolkitOperationBase extends PluginBase implements ImageToolkitOperationInterface { @@ -39,70 +37,22 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi } /** - * Validates and normalizes 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 validateArguments(array $arguments) { - $manager = \Drupal::typedDataManager(); - - // Get arguments definition. - $definition = $this->getPluginDefinition()['arguments']; - - foreach ($definition as $id => $argument) { - - // The defined argument has been provided. - if (array_key_exists($id, $arguments)) { - $data_definition = DataDefinition::create($argument['type']); - $typed_data = $manager->create($data_definition, $arguments[$id]); - $violations = $typed_data->validate(); - - // There are violations against defined TypedData. - if ($violations->count()) { - $fail = TRUE; - - // One more try: Check if casted value passes. - if (method_exists($typed_data, 'getCastedValue')) { - $casted = $typed_data->getCastedValue(); - $typed_data->setValue($casted); - $fail = (bool) $typed_data->validate()->count(); - } - - if ($fail) { - $message_arguments = array('@value' => $arguments[$id], '@plugin' => $this->getPluginId(), '@arg' => $id, '@type' => $argument['type']); - $message = String::format("The value '@value' provided to '@plugin' plugin in '@arg' argument cannot be casted as '@type'.", $message_arguments); - throw new \InvalidArgumentException($message); - } - } - } - // A defined argument hasn't been passed. - else { + public function prepare(ImageInterface $image, array &$arguments) { + foreach ($this->getPluginDefinition()['arguments'] as $id => $argument) { + // The defined argument hasn't been provided. + if (!array_key_exists($id, $arguments)) { if ($argument['required']) { // If the argument is required throw an exception. - $message = String::format("Argument '@arg' expected by plugin '@plugin' but not passed.", array('@arg' => $id, '@plugin' => $this->getPluginId())); - throw new \InvalidArgumentException($message); + throw new \InvalidArgumentException("Argument '$id' expected by plugin '" . $this->getPluginId() . "' but not passed."); } else { - // Optional argument? Assign the default value. + // Optional argument? Assign the default value or NULL. $arguments[$id] = array_key_exists('default', $argument) ? $argument['default'] : NULL; } } } - - return $arguments; - } - - /** - * {@inheritdoc} - */ - public function prepare(ImageInterface $image, array &$arguments) { - $arguments = $this->validateArguments($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 fa03ecf..e2507de 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 @@ -21,19 +21,15 @@ * arguments = { * "x" = { * "description" = "The starting x offset at which to start the crop, in pixels", - * "type" = "integer" * }, * "y" = { * "description" = "The starting y offset at which to start the crop, in pixels", - * "type" = "integer" * }, * "width" = { * "description" = "The width of the cropped area, in pixels", - * "type" = "integer" * }, * "height" = { * "description" = "The height of the cropped area, in pixels", - * "type" = "integer" * } * } * ) 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 663e4e3..8fc0286 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 @@ -21,11 +21,9 @@ * arguments = { * "width" = { * "description" = "The new width of the resized image, in pixels", - * "type" = "integer" * }, * "height" = { * "description" = "The new height of the resized image, in pixels", - * "type" = "integer" * } * } * ) 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 b90e4f2..0b14d40 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 @@ -21,11 +21,9 @@ * arguments = { * "degrees" = { * "description" = "The number of (clockwise) degrees to rotate the image", - * "type" = "float" * }, * "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", - * "type" = "integer", * "required" = FALSE, * "default" = NULL * } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Scale.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Scale.php index fe414b1..e189e34 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Scale.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/gd/Scale.php @@ -21,19 +21,16 @@ * arguments = { * "width" = { * "description" = "The target width, in pixels. This value is omitted then the scaling will based only on the height value", - * "type" = "integer", * "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", - * "type" = "integer", * "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", - * "type" = "boolean", * "required" = FALSE, * "default" = FALSE * } 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 7ce04e9..637ec8c 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 @@ -21,11 +21,9 @@ * arguments = { * "width" = { * "description" = "The target width, in pixels", - * "type" = "integer" * }, * "height" = { * "description" = "The target height, in pixels", - * "type" = "integer" * } * } * ) 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 6e87309..7406cc5 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 @@ -21,19 +21,15 @@ * arguments = { * "x" = { * "description" = "The starting x offset at which to start the crop, in pixels", - * "type" = "integer" * }, * "y" = { * "description" = "The starting y offset at which to start the crop, in pixels", - * "type" = "integer" * }, * "width" = { * "description" = "The width of the cropped area, in pixels", - * "type" = "integer" * }, * "height" = { * "description" = "The height of the cropped area, in pixels", - * "type" = "integer" * } * } * ) 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 4c56480..85047a0 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 @@ -21,11 +21,9 @@ * arguments = { * "width" = { * "description" = "The new width of the resized image, in pixels", - * "type" = "integer" * }, * "height" = { * "description" = "The new height of the resized image, in pixels", - * "type" = "integer" * } * } * ) 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 e2fb41a..2fc0b09 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 @@ -21,11 +21,9 @@ * arguments = { * "degrees" = { * "description" = "The number of (clockwise) degrees to rotate the image", - * "type" = "float" * }, * "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", - * "type" = "integer", * "required" = FALSE, * "default" = NULL * } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Scale.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Scale.php index f6cd0c1..9096041 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Scale.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/test/Scale.php @@ -20,19 +20,16 @@ * arguments = { * "width" = { * "description" = "The target width, in pixels. This value is omitted then the scaling will based only on the height value", - * "type" = "integer", * "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", - * "type" = "integer", * "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", - * "type" = "boolean", * "required" = FALSE, * "default" = FALSE * } 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 f0c9a6c..697835a 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 @@ -20,11 +20,9 @@ * arguments = { * "width" = { * "description" = "The target width, in pixels", - * "type" = "integer" * }, * "height" = { * "description" = "The target height, in pixels", - * "type" = "integer" * } * } * )