Mercurial > hg > isophonics-drupal-site
comparison core/modules/image/src/ImageEffectBase.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\image; | |
4 | |
5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | |
6 use Drupal\Core\Plugin\PluginBase; | |
7 use Psr\Log\LoggerInterface; | |
8 use Symfony\Component\DependencyInjection\ContainerInterface; | |
9 | |
10 /** | |
11 * Provides a base class for image effects. | |
12 * | |
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 | |
18 * @see plugin_api | |
19 */ | |
20 abstract class ImageEffectBase extends PluginBase implements ImageEffectInterface, ContainerFactoryPluginInterface { | |
21 | |
22 /** | |
23 * The image effect ID. | |
24 * | |
25 * @var string | |
26 */ | |
27 protected $uuid; | |
28 | |
29 /** | |
30 * The weight of the image effect. | |
31 * | |
32 * @var int|string | |
33 */ | |
34 protected $weight = ''; | |
35 | |
36 /** | |
37 * A logger instance. | |
38 * | |
39 * @var \Psr\Log\LoggerInterface | |
40 */ | |
41 protected $logger; | |
42 | |
43 /** | |
44 * {@inheritdoc} | |
45 */ | |
46 public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger) { | |
47 parent::__construct($configuration, $plugin_id, $plugin_definition); | |
48 | |
49 $this->setConfiguration($configuration); | |
50 $this->logger = $logger; | |
51 } | |
52 | |
53 /** | |
54 * {@inheritdoc} | |
55 */ | |
56 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
57 return new static( | |
58 $configuration, | |
59 $plugin_id, | |
60 $plugin_definition, | |
61 $container->get('logger.factory')->get('image') | |
62 ); | |
63 } | |
64 | |
65 /** | |
66 * {@inheritdoc} | |
67 */ | |
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. | |
72 } | |
73 | |
74 /** | |
75 * {@inheritdoc} | |
76 */ | |
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. | |
81 return $extension; | |
82 } | |
83 | |
84 /** | |
85 * {@inheritdoc} | |
86 */ | |
87 public function getSummary() { | |
88 return [ | |
89 '#markup' => '', | |
90 '#effect' => [ | |
91 'id' => $this->pluginDefinition['id'], | |
92 'label' => $this->label(), | |
93 'description' => $this->pluginDefinition['description'], | |
94 ], | |
95 ]; | |
96 } | |
97 | |
98 /** | |
99 * {@inheritdoc} | |
100 */ | |
101 public function label() { | |
102 return $this->pluginDefinition['label']; | |
103 } | |
104 | |
105 /** | |
106 * {@inheritdoc} | |
107 */ | |
108 public function getUuid() { | |
109 return $this->uuid; | |
110 } | |
111 | |
112 /** | |
113 * {@inheritdoc} | |
114 */ | |
115 public function setWeight($weight) { | |
116 $this->weight = $weight; | |
117 return $this; | |
118 } | |
119 | |
120 /** | |
121 * {@inheritdoc} | |
122 */ | |
123 public function getWeight() { | |
124 return $this->weight; | |
125 } | |
126 | |
127 /** | |
128 * {@inheritdoc} | |
129 */ | |
130 public function getConfiguration() { | |
131 return [ | |
132 'uuid' => $this->getUuid(), | |
133 'id' => $this->getPluginId(), | |
134 'weight' => $this->getWeight(), | |
135 'data' => $this->configuration, | |
136 ]; | |
137 } | |
138 | |
139 /** | |
140 * {@inheritdoc} | |
141 */ | |
142 public function setConfiguration(array $configuration) { | |
143 $configuration += [ | |
144 'data' => [], | |
145 'uuid' => '', | |
146 'weight' => '', | |
147 ]; | |
148 $this->configuration = $configuration['data'] + $this->defaultConfiguration(); | |
149 $this->uuid = $configuration['uuid']; | |
150 $this->weight = $configuration['weight']; | |
151 return $this; | |
152 } | |
153 | |
154 /** | |
155 * {@inheritdoc} | |
156 */ | |
157 public function defaultConfiguration() { | |
158 return []; | |
159 } | |
160 | |
161 /** | |
162 * {@inheritdoc} | |
163 */ | |
164 public function calculateDependencies() { | |
165 return []; | |
166 } | |
167 | |
168 } |