Issue #3420996 by mstrelan, kim.pepper, larowlan: Convert ImageEffect plugin discovery to attributes
parent
1366a3ae13
commit
58ecf6d433
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\image\Attribute;
|
||||
|
||||
use Drupal\Component\Plugin\Attribute\Plugin;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Defines an ImageEffect attribute for plugin discovery.
|
||||
*
|
||||
* Plugin Namespace: Plugin\ImageEffect
|
||||
*
|
||||
* For a working example, see
|
||||
* \Drupal\image\Plugin\ImageEffect\ResizeImageEffect
|
||||
*
|
||||
* @see hook_image_effect_info_alter()
|
||||
* @see \Drupal\image\ConfigurableImageEffectInterface
|
||||
* @see \Drupal\image\ConfigurableImageEffectBase
|
||||
* @see \Drupal\image\ImageEffectInterface
|
||||
* @see \Drupal\image\ImageEffectBase
|
||||
* @see \Drupal\image\ImageEffectManager
|
||||
* @see \Drupal\Core\ImageToolkit\Annotation\ImageToolkitOperation
|
||||
* @see plugin_api
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class ImageEffect extends Plugin {
|
||||
|
||||
/**
|
||||
* Constructs an ImageEffect attribute.
|
||||
*
|
||||
* @param string $id
|
||||
* The plugin ID.
|
||||
* @param \Drupal\Core\StringTranslation\TranslatableMarkup $label
|
||||
* The human-readable name of the image effect.
|
||||
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
|
||||
* (optional) A brief description of the image effect. This will be shown
|
||||
* when adding or configuring this image effect.
|
||||
* @param class-string|null $deriver
|
||||
* (optional) The deriver class.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $id,
|
||||
public readonly TranslatableMarkup $label,
|
||||
public readonly ?TranslatableMarkup $description = NULL,
|
||||
public readonly ?string $deriver = NULL,
|
||||
) {}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace Drupal\image;
|
|||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
use Drupal\image\Attribute\ImageEffect;
|
||||
|
||||
/**
|
||||
* Manages image effect plugins.
|
||||
|
@ -31,7 +32,7 @@ class ImageEffectManager extends DefaultPluginManager {
|
|||
* The module handler.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Plugin/ImageEffect', $namespaces, $module_handler, 'Drupal\image\ImageEffectInterface', 'Drupal\image\Annotation\ImageEffect');
|
||||
parent::__construct('Plugin/ImageEffect', $namespaces, $module_handler, 'Drupal\image\ImageEffectInterface', ImageEffect::class, 'Drupal\image\Annotation\ImageEffect');
|
||||
|
||||
$this->alterInfo('image_effect_info');
|
||||
$this->setCacheBackend($cache_backend, 'image_effect_plugins');
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue