diff --git a/core/lib/Drupal/Core/ImageToolkit/Attribute/ImageToolkit.php b/core/lib/Drupal/Core/ImageToolkit/Attribute/ImageToolkit.php new file mode 100644 index 0000000000000000000000000000000000000000..c6069cfd6a361eb60e6010b17aae4f947974dc42 --- /dev/null +++ b/core/lib/Drupal/Core/ImageToolkit/Attribute/ImageToolkit.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Core\ImageToolkit\Attribute; + +use Drupal\Component\Plugin\Attribute\Plugin; +use Drupal\Core\StringTranslation\TranslatableMarkup; + +/** + * Defines a Plugin attribute for the image toolkit plugin. + * + * An image toolkit provides common image file manipulations like scaling, + * cropping, and rotating. + * + * Plugin namespace: Plugin\ImageToolkit + * + * For a working example, see + * \Drupal\system\Plugin\ImageToolkit\GDToolkit + * + * @see \Drupal\Core\ImageToolkit\Annotation\ImageToolkitOperation + * @see \Drupal\Core\ImageToolkit\ImageToolkitInterface + * @see \Drupal\Core\ImageToolkit\ImageToolkitBase + * @see \Drupal\Core\ImageToolkit\ImageToolkitManager + * @see plugin_api + */ +#[\Attribute(\Attribute::TARGET_CLASS)] +class ImageToolkit extends Plugin { + + public function __construct( + public readonly string $id, + public readonly TranslatableMarkup $title, + public readonly ?string $deriver = NULL, + ) {} + +} diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php index d53364704fedaaaa7162b1336b27a42c0817aa09..2508b0dda81f44ae816216d0dd1c6723a2c8d02b 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php @@ -5,6 +5,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\ImageToolkit\Attribute\ImageToolkit; use Drupal\Core\Plugin\DefaultPluginManager; /** @@ -38,7 +39,14 @@ class ImageToolkitManager extends DefaultPluginManager { * The config factory. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) { - parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\ImageToolkitInterface', 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit'); + parent::__construct( + 'Plugin/ImageToolkit', + $namespaces, + $module_handler, + ImageToolkitInterface::class, + ImageToolkit::class, + 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit', + ); $this->setCacheBackend($cache_backend, 'image_toolkit_plugins'); $this->configFactory = $config_factory; diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 977280cc764c39653e93d0a5a7f75358677b781e..59ec59ee31fa24bca5fbe48880bac68268920274 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -7,11 +7,13 @@ use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\ImageToolkit\Attribute\ImageToolkit; use Drupal\Core\ImageToolkit\ImageToolkitBase; use Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -19,12 +21,11 @@ /** * Defines the GD2 toolkit for image manipulation within Drupal. - * - * @ImageToolkit( - * id = "gd", - * title = @Translation("GD2 image manipulation toolkit") - * ) */ +#[ImageToolkit( + id: "gd", + title: new TranslatableMarkup("GD2 image manipulation toolkit"), +)] class GDToolkit extends ImageToolkitBase { /** diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/BrokenToolkit.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/BrokenToolkit.php index d5b9df451d76514b3a22ef5ae3e4c7c79ae1c540..dba74dde4f0f16081cbe43b621cddda051716d75 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/BrokenToolkit.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/BrokenToolkit.php @@ -2,14 +2,16 @@ namespace Drupal\image_test\Plugin\ImageToolkit; +use Drupal\Core\ImageToolkit\Attribute\ImageToolkit; +use Drupal\Core\StringTranslation\TranslatableMarkup; + /** * Defines a Test toolkit for image manipulation within Drupal. - * - * @ImageToolkit( - * id = "broken", - * title = @Translation("A dummy toolkit that is broken") - * ) */ +#[ImageToolkit( + id: "broken", + title: new TranslatableMarkup("A dummy toolkit that is broken"), +)] class BrokenToolkit extends TestToolkit { /** diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/DerivedToolkit.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/DerivedToolkit.php index 55e86497ee5cf9241b6476bc04bfe0ab0d2031a5..94e08961573045f972297ef6bcb50b5007fb19e5 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/DerivedToolkit.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/DerivedToolkit.php @@ -2,12 +2,14 @@ namespace Drupal\image_test\Plugin\ImageToolkit; +use Drupal\Core\ImageToolkit\Attribute\ImageToolkit; +use Drupal\Core\StringTranslation\TranslatableMarkup; + /** * Provides a derivative of TestToolkit. - * - * @ImageToolkit( - * id = "test:derived_toolkit", - * title = @Translation("A dummy toolkit, derivative of 'test'.") - * ) */ +#[ImageToolkit( + id: "test:derived_toolkit", + title: new TranslatableMarkup("A dummy toolkit, derivative of 'test'."), +)] class DerivedToolkit extends TestToolkit {} diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php index 09600e573495b24ea54830a1a5bcd6409a1078fc..0d62ee61c65db93b739b0ae45936059a6bb2afbe 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php @@ -4,20 +4,21 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\ImageToolkit\Attribute\ImageToolkit; use Drupal\Core\ImageToolkit\ImageToolkitBase; use Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface; use Drupal\Core\State\StateInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a Test toolkit for image manipulation within Drupal. - * - * @ImageToolkit( - * id = "test", - * title = @Translation("A dummy toolkit that works") - * ) */ +#[ImageToolkit( + id: "test", + title: new TranslatableMarkup("A dummy toolkit that works"), +)] class TestToolkit extends ImageToolkitBase { /**