Loading core/lib/Drupal/Core/ImageToolkit/Attribute/ImageToolkit.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?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, ) {} } core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +9 −1 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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; Loading core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +6 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { /** Loading core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/BrokenToolkit.php +7 −5 Original line number Diff line number Diff line Loading @@ -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 { /** Loading core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/DerivedToolkit.php +7 −5 Original line number Diff line number Diff line Loading @@ -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 {} Loading
core/lib/Drupal/Core/ImageToolkit/Attribute/ImageToolkit.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?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, ) {} }
core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +9 −1 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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; Loading
core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +6 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { /** Loading
core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/BrokenToolkit.php +7 −5 Original line number Diff line number Diff line Loading @@ -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 { /** Loading
core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/DerivedToolkit.php +7 −5 Original line number Diff line number Diff line Loading @@ -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 {}