Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\image;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
Chris@0
|
6 use Drupal\Core\Plugin\PluginBase;
|
Chris@0
|
7 use Psr\Log\LoggerInterface;
|
Chris@0
|
8 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Provides a base class for image effects.
|
Chris@0
|
12 *
|
Chris@0
|
13 * @see \Drupal\image\Annotation\ImageEffect
|
Chris@0
|
14 * @see \Drupal\image\ImageEffectInterface
|
Chris@0
|
15 * @see \Drupal\image\ConfigurableImageEffectInterface
|
Chris@0
|
16 * @see \Drupal\image\ConfigurableImageEffectBase
|
Chris@0
|
17 * @see \Drupal\image\ImageEffectManager
|
Chris@0
|
18 * @see plugin_api
|
Chris@0
|
19 */
|
Chris@0
|
20 abstract class ImageEffectBase extends PluginBase implements ImageEffectInterface, ContainerFactoryPluginInterface {
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * The image effect ID.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @var string
|
Chris@0
|
26 */
|
Chris@0
|
27 protected $uuid;
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * The weight of the image effect.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @var int|string
|
Chris@0
|
33 */
|
Chris@0
|
34 protected $weight = '';
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * A logger instance.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @var \Psr\Log\LoggerInterface
|
Chris@0
|
40 */
|
Chris@0
|
41 protected $logger;
|
Chris@0
|
42
|
Chris@0
|
43 /**
|
Chris@0
|
44 * {@inheritdoc}
|
Chris@0
|
45 */
|
Chris@0
|
46 public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger) {
|
Chris@0
|
47 parent::__construct($configuration, $plugin_id, $plugin_definition);
|
Chris@0
|
48
|
Chris@0
|
49 $this->setConfiguration($configuration);
|
Chris@0
|
50 $this->logger = $logger;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * {@inheritdoc}
|
Chris@0
|
55 */
|
Chris@0
|
56 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
Chris@0
|
57 return new static(
|
Chris@0
|
58 $configuration,
|
Chris@0
|
59 $plugin_id,
|
Chris@0
|
60 $plugin_definition,
|
Chris@0
|
61 $container->get('logger.factory')->get('image')
|
Chris@0
|
62 );
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 /**
|
Chris@0
|
66 * {@inheritdoc}
|
Chris@0
|
67 */
|
Chris@0
|
68 public function transformDimensions(array &$dimensions, $uri) {
|
Chris@0
|
69 // Most image effects will not change the dimensions. This base
|
Chris@0
|
70 // implementation represents this behavior. Override this method if your
|
Chris@0
|
71 // image effect does change the dimensions.
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * {@inheritdoc}
|
Chris@0
|
76 */
|
Chris@0
|
77 public function getDerivativeExtension($extension) {
|
Chris@0
|
78 // Most image effects will not change the extension. This base
|
Chris@0
|
79 // implementation represents this behavior. Override this method if your
|
Chris@0
|
80 // image effect does change the extension.
|
Chris@0
|
81 return $extension;
|
Chris@0
|
82 }
|
Chris@0
|
83
|
Chris@0
|
84 /**
|
Chris@0
|
85 * {@inheritdoc}
|
Chris@0
|
86 */
|
Chris@0
|
87 public function getSummary() {
|
Chris@0
|
88 return [
|
Chris@0
|
89 '#markup' => '',
|
Chris@0
|
90 '#effect' => [
|
Chris@0
|
91 'id' => $this->pluginDefinition['id'],
|
Chris@0
|
92 'label' => $this->label(),
|
Chris@0
|
93 'description' => $this->pluginDefinition['description'],
|
Chris@0
|
94 ],
|
Chris@0
|
95 ];
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@0
|
98 /**
|
Chris@0
|
99 * {@inheritdoc}
|
Chris@0
|
100 */
|
Chris@0
|
101 public function label() {
|
Chris@0
|
102 return $this->pluginDefinition['label'];
|
Chris@0
|
103 }
|
Chris@0
|
104
|
Chris@0
|
105 /**
|
Chris@0
|
106 * {@inheritdoc}
|
Chris@0
|
107 */
|
Chris@0
|
108 public function getUuid() {
|
Chris@0
|
109 return $this->uuid;
|
Chris@0
|
110 }
|
Chris@0
|
111
|
Chris@0
|
112 /**
|
Chris@0
|
113 * {@inheritdoc}
|
Chris@0
|
114 */
|
Chris@0
|
115 public function setWeight($weight) {
|
Chris@0
|
116 $this->weight = $weight;
|
Chris@0
|
117 return $this;
|
Chris@0
|
118 }
|
Chris@0
|
119
|
Chris@0
|
120 /**
|
Chris@0
|
121 * {@inheritdoc}
|
Chris@0
|
122 */
|
Chris@0
|
123 public function getWeight() {
|
Chris@0
|
124 return $this->weight;
|
Chris@0
|
125 }
|
Chris@0
|
126
|
Chris@0
|
127 /**
|
Chris@0
|
128 * {@inheritdoc}
|
Chris@0
|
129 */
|
Chris@0
|
130 public function getConfiguration() {
|
Chris@0
|
131 return [
|
Chris@0
|
132 'uuid' => $this->getUuid(),
|
Chris@0
|
133 'id' => $this->getPluginId(),
|
Chris@0
|
134 'weight' => $this->getWeight(),
|
Chris@0
|
135 'data' => $this->configuration,
|
Chris@0
|
136 ];
|
Chris@0
|
137 }
|
Chris@0
|
138
|
Chris@0
|
139 /**
|
Chris@0
|
140 * {@inheritdoc}
|
Chris@0
|
141 */
|
Chris@0
|
142 public function setConfiguration(array $configuration) {
|
Chris@0
|
143 $configuration += [
|
Chris@0
|
144 'data' => [],
|
Chris@0
|
145 'uuid' => '',
|
Chris@0
|
146 'weight' => '',
|
Chris@0
|
147 ];
|
Chris@0
|
148 $this->configuration = $configuration['data'] + $this->defaultConfiguration();
|
Chris@0
|
149 $this->uuid = $configuration['uuid'];
|
Chris@0
|
150 $this->weight = $configuration['weight'];
|
Chris@0
|
151 return $this;
|
Chris@0
|
152 }
|
Chris@0
|
153
|
Chris@0
|
154 /**
|
Chris@0
|
155 * {@inheritdoc}
|
Chris@0
|
156 */
|
Chris@0
|
157 public function defaultConfiguration() {
|
Chris@0
|
158 return [];
|
Chris@0
|
159 }
|
Chris@0
|
160
|
Chris@0
|
161 /**
|
Chris@0
|
162 * {@inheritdoc}
|
Chris@0
|
163 */
|
Chris@0
|
164 public function calculateDependencies() {
|
Chris@0
|
165 return [];
|
Chris@0
|
166 }
|
Chris@0
|
167
|
Chris@0
|
168 }
|