3 namespace Drupal\image;
5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
6 use Drupal\Core\Plugin\PluginBase;
7 use Psr\Log\LoggerInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides a base class for image effects.
13 * @see \Drupal\image\Annotation\ImageEffect
14 * @see \Drupal\image\ImageEffectInterface
15 * @see \Drupal\image\ConfigurableImageEffectInterface
16 * @see \Drupal\image\ConfigurableImageEffectBase
17 * @see \Drupal\image\ImageEffectManager
20 abstract class ImageEffectBase extends PluginBase implements ImageEffectInterface, ContainerFactoryPluginInterface {
23 * The image effect ID.
30 * The weight of the image effect.
34 protected $weight = '';
39 * @var \Psr\Log\LoggerInterface
46 public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger) {
47 parent::__construct($configuration, $plugin_id, $plugin_definition);
49 $this->setConfiguration($configuration);
50 $this->logger = $logger;
56 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
61 $container->get('logger.factory')->get('image')
68 public function transformDimensions(array &$dimensions, $uri) {
69 // Most image effects will not change the dimensions. This base
70 // implementation represents this behavior. Override this method if your
71 // image effect does change the dimensions.
77 public function getDerivativeExtension($extension) {
78 // Most image effects will not change the extension. This base
79 // implementation represents this behavior. Override this method if your
80 // image effect does change the extension.
87 public function getSummary() {
91 'id' => $this->pluginDefinition['id'],
92 'label' => $this->label(),
93 'description' => $this->pluginDefinition['description'],
101 public function label() {
102 return $this->pluginDefinition['label'];
108 public function getUuid() {
115 public function setWeight($weight) {
116 $this->weight = $weight;
123 public function getWeight() {
124 return $this->weight;
130 public function getConfiguration() {
132 'uuid' => $this->getUuid(),
133 'id' => $this->getPluginId(),
134 'weight' => $this->getWeight(),
135 'data' => $this->configuration,
142 public function setConfiguration(array $configuration) {
148 $this->configuration = $configuration['data'] + $this->defaultConfiguration();
149 $this->uuid = $configuration['uuid'];
150 $this->weight = $configuration['weight'];
157 public function defaultConfiguration() {
164 public function calculateDependencies() {