Verified Commit e8b4e5c2 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3420991 by kim.pepper, larowlan, mstrelan: Convert ImageToolkit plugin...

Issue #3420991 by kim.pepper, larowlan, mstrelan: Convert ImageToolkit plugin discovery to attributes

(cherry picked from commit ffaf9871)
parent 4eed1aa1
Loading
Loading
Loading
Loading
+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,
  ) {}

}
+9 −1
Original line number Diff line number Diff line
@@ -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;
+6 −5
Original line number Diff line number Diff line
@@ -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 {

  /**
+7 −5
Original line number Diff line number Diff line
@@ -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 {

  /**
+7 −5
Original line number Diff line number Diff line
@@ -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