From 58ecf6d433e8279b43588e9cfa86f59db3b40376 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 28 Feb 2024 23:28:27 +0000 Subject: [PATCH] Issue #3420996 by mstrelan, kim.pepper, larowlan: Convert ImageEffect plugin discovery to attributes --- .../image/src/Attribute/ImageEffect.php | 50 +++++++++++++++++++ core/modules/image/src/ImageEffectManager.php | 3 +- .../Plugin/ImageEffect/ConvertImageEffect.php | 13 ++--- .../Plugin/ImageEffect/CropImageEffect.php | 13 ++--- .../ImageEffect/DesaturateImageEffect.php | 13 ++--- .../Plugin/ImageEffect/ResizeImageEffect.php | 13 ++--- .../Plugin/ImageEffect/RotateImageEffect.php | 13 ++--- .../ImageEffect/ScaleAndCropImageEffect.php | 13 ++--- .../Plugin/ImageEffect/ScaleImageEffect.php | 13 ++--- .../ImageEffect/AjaxTestImageEffect.php | 11 ++-- .../ImageEffect/NullTestImageEffect.php | 11 ++-- .../UriDependentTestImageEffect.php | 11 ++-- 12 files changed, 119 insertions(+), 58 deletions(-) create mode 100644 core/modules/image/src/Attribute/ImageEffect.php diff --git a/core/modules/image/src/Attribute/ImageEffect.php b/core/modules/image/src/Attribute/ImageEffect.php new file mode 100644 index 00000000000..bcfd4aecd1b --- /dev/null +++ b/core/modules/image/src/Attribute/ImageEffect.php @@ -0,0 +1,50 @@ +alterInfo('image_effect_info'); $this->setCacheBackend($cache_backend, 'image_effect_plugins'); diff --git a/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php index 4e848326cf6..d8efa2f618d 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php @@ -4,17 +4,18 @@ namespace Drupal\image\Plugin\ImageEffect; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; use Drupal\image\ConfigurableImageEffectBase; /** * Converts an image resource. - * - * @ImageEffect( - * id = "image_convert", - * label = @Translation("Convert"), - * description = @Translation("Converts an image to a format (such as JPEG).") - * ) */ +#[ImageEffect( + id: "image_convert", + label: new TranslatableMarkup("Convert"), + description: new TranslatableMarkup("Converts an image to a format (such as JPEG)."), +)] class ConvertImageEffect extends ConfigurableImageEffectBase { /** diff --git a/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php index 8f99de88134..accdfe17b88 100644 --- a/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php @@ -4,16 +4,17 @@ namespace Drupal\image\Plugin\ImageEffect; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; /** * Crops an image resource. - * - * @ImageEffect( - * id = "image_crop", - * label = @Translation("Crop"), - * description = @Translation("Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately.") - * ) */ +#[ImageEffect( + id: "image_crop", + label: new TranslatableMarkup("Crop"), + description: new TranslatableMarkup("Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately."), +)] class CropImageEffect extends ResizeImageEffect { /** diff --git a/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php index d34161ecc59..6ce42cf2ff9 100644 --- a/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/DesaturateImageEffect.php @@ -3,17 +3,18 @@ namespace Drupal\image\Plugin\ImageEffect; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; use Drupal\image\ImageEffectBase; /** * Desaturates (grayscale) an image resource. - * - * @ImageEffect( - * id = "image_desaturate", - * label = @Translation("Desaturate"), - * description = @Translation("Desaturate converts an image to grayscale.") - * ) */ +#[ImageEffect( + id: "image_desaturate", + label: new TranslatableMarkup("Desaturate"), + description: new TranslatableMarkup("Desaturate converts an image to grayscale."), +)] class DesaturateImageEffect extends ImageEffectBase { /** diff --git a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php index 26f70705db4..ea49e4b23d6 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php @@ -4,17 +4,18 @@ namespace Drupal\image\Plugin\ImageEffect; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; use Drupal\image\ConfigurableImageEffectBase; /** * Resizes an image resource. - * - * @ImageEffect( - * id = "image_resize", - * label = @Translation("Resize"), - * description = @Translation("Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately.") - * ) */ +#[ImageEffect( + id: "image_resize", + label: new TranslatableMarkup("Resize"), + description: new TranslatableMarkup("Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately."), +)] class ResizeImageEffect extends ConfigurableImageEffectBase { /** diff --git a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php index d6453dbf946..2353e64bac9 100644 --- a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php @@ -6,17 +6,18 @@ use Drupal\Component\Utility\Color; use Drupal\Component\Utility\Rectangle; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; use Drupal\image\ConfigurableImageEffectBase; /** * Rotates an image resource. - * - * @ImageEffect( - * id = "image_rotate", - * label = @Translation("Rotate"), - * description = @Translation("Rotating an image may cause the dimensions of an image to increase to fit the diagonal.") - * ) */ +#[ImageEffect( + id: "image_rotate", + label: new TranslatableMarkup("Rotate"), + description: new TranslatableMarkup("Rotating an image may cause the dimensions of an image to increase to fit the diagonal.") +)] class RotateImageEffect extends ConfigurableImageEffectBase { /** diff --git a/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php index b496341a417..73489d7acec 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php @@ -3,16 +3,17 @@ namespace Drupal\image\Plugin\ImageEffect; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; /** * Scales and crops an image resource. - * - * @ImageEffect( - * id = "image_scale_and_crop", - * label = @Translation("Scale and crop"), - * description = @Translation("Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.") - * ) */ +#[ImageEffect( + id: "image_scale_and_crop", + label: new TranslatableMarkup("Scale and crop"), + description: new TranslatableMarkup("Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.") +)] class ScaleAndCropImageEffect extends CropImageEffect { /** diff --git a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php index 13e5aaa2d2f..7019260c2ae 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php @@ -5,16 +5,17 @@ namespace Drupal\image\Plugin\ImageEffect; use Drupal\Component\Utility\Image; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; /** * Scales an image resource. - * - * @ImageEffect( - * id = "image_scale", - * label = @Translation("Scale"), - * description = @Translation("Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.") - * ) */ +#[ImageEffect( + id: "image_scale", + label: new TranslatableMarkup("Scale"), + description: new TranslatableMarkup("Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.") +)] class ScaleImageEffect extends ResizeImageEffect { /** diff --git a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php index 1a8cfd7eea8..a952afeb380 100644 --- a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php +++ b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php @@ -6,16 +6,17 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; use Drupal\image\ConfigurableImageEffectBase; /** * Provides a test effect using Ajax in the configuration form. - * - * @ImageEffect( - * id = "image_module_test_ajax", - * label = @Translation("Ajax test") - * ) */ +#[ImageEffect( + id: "image_module_test_ajax", + label: new TranslatableMarkup("Ajax test") +)] class AjaxTestImageEffect extends ConfigurableImageEffectBase { /** diff --git a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php index ceca6fac34a..19e31a22e5f 100644 --- a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php +++ b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/NullTestImageEffect.php @@ -3,16 +3,17 @@ namespace Drupal\image_module_test\Plugin\ImageEffect; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; use Drupal\image\ImageEffectBase; /** * Performs no operation on an image resource. - * - * @ImageEffect( - * id = "image_module_test_null", - * label = @Translation("Image module test") - * ) */ +#[ImageEffect( + id: "image_module_test_null", + label: new TranslatableMarkup("Image module test") +)] class NullTestImageEffect extends ImageEffectBase { /** diff --git a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php index 5e5ddc72bcd..457314c8057 100644 --- a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php +++ b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php @@ -3,16 +3,17 @@ namespace Drupal\image_module_test\Plugin\ImageEffect; use Drupal\Core\Image\ImageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\image\Attribute\ImageEffect; use Drupal\image\ImageEffectBase; /** * Performs an image operation that depends on the URI of the original image. - * - * @ImageEffect( - * id = "image_module_test_uri_dependent", - * label = @Translation("URI dependent test image effect") - * ) */ +#[ImageEffect( + id: "image_module_test_uri_dependent", + label: new TranslatableMarkup("URI dependent test image effect") +)] class UriDependentTestImageEffect extends ImageEffectBase { /**