Skip to content

Commit 6a90a61

Browse files
committed
Merge branch 'release/1.5.5' into v1
2 parents 18b6e60 + 02da7d8 commit 6a90a61

File tree

7 files changed

+84
-37
lines changed

7 files changed

+84
-37
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ImageOptimize Changelog
22

3+
## 1.5.5 - 2019.04.22
4+
### Changed
5+
* Updated Twig namespacing to be compliant with deprecated class aliases in 2.7.x
6+
37
## 1.5.4 - 2019.02.22
48
### Changed
59
* Fixed an issue where focal points weren't always respected for Imgix

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nystudio107/craft-imageoptimize",
33
"description": "Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.",
44
"type": "craft-plugin",
5-
"version": "1.5.4",
5+
"version": "1.5.5",
66
"keywords": [
77
"craft",
88
"cms",

src/ImageOptimize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function settingsHtml()
190190
'imageTransform' => ImageOptimize::$plugin->transformMethod,
191191
]
192192
);
193-
} catch (\Twig_Error_Loader $e) {
193+
} catch (\Twig\Error\LoaderError $e) {
194194
Craft::error($e->getMessage(), __METHOD__);
195195
} catch (Exception $e) {
196196
Craft::error($e->getMessage(), __METHOD__);

src/fields/OptimizedImages.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,21 @@ public function rules()
151151
{
152152
$rules = parent::rules();
153153
$rules = array_merge($rules, [
154-
['variants', ArrayValidator::class],
154+
[
155+
[
156+
'displayOptimizedImageVariants',
157+
'displayDominantColorPalette',
158+
'displayLazyLoadPlaceholderImages',
159+
],
160+
'boolean',
161+
],
162+
[
163+
[
164+
'ignoreFilesOfType',
165+
'variants',
166+
],
167+
ArrayValidator::class
168+
],
155169
]);
156170

157171
return $rules;
@@ -236,7 +250,7 @@ public function getSettingsHtml()
236250
[
237251
]
238252
);
239-
} catch (\Twig_Error_Loader $e) {
253+
} catch (\Twig\Error\LoaderError $e) {
240254
Craft::error($e->getMessage(), __METHOD__);
241255
} catch (\yii\base\Exception $e) {
242256
Craft::error($e->getMessage(), __METHOD__);
@@ -283,7 +297,7 @@ public function getSettingsHtml()
283297
'namespace' => $namespacedId,
284298
]
285299
);
286-
} catch (\Twig_Error_Loader $e) {
300+
} catch (\Twig\Error\LoaderError $e) {
287301
Craft::error($e->getMessage(), __METHOD__);
288302
} catch (\yii\base\Exception $e) {
289303
Craft::error($e->getMessage(), __METHOD__);
@@ -339,7 +353,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
339353
'nameSpaceId' => $nameSpaceId,
340354
]
341355
);
342-
} catch (\Twig_Error_Loader $e) {
356+
} catch (\Twig\Error\LoaderError $e) {
343357
Craft::error($e->getMessage(), __METHOD__);
344358
} catch (\yii\base\Exception $e) {
345359
Craft::error($e->getMessage(), __METHOD__);
@@ -353,7 +367,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
353367
[
354368
]
355369
);
356-
} catch (\Twig_Error_Loader $e) {
370+
} catch (\Twig\Error\LoaderError $e) {
357371
Craft::error($e->getMessage(), __METHOD__);
358372
} catch (\yii\base\Exception $e) {
359373
Craft::error($e->getMessage(), __METHOD__);

src/models/OptimizedImage.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function rules(): array
117117
*
118118
* @param int $width
119119
*
120-
* @return \Twig_Markup|null
120+
* @return \Twig\Markup|null
121121
*/
122122
public function src(int $width = 0): string
123123
{
@@ -133,7 +133,7 @@ public function src(int $width = 0): string
133133
*
134134
* @param int $width
135135
*
136-
* @return null|string|\Twig_Markup
136+
* @return null|string|\Twig\Markup
137137
*/
138138
public function getSrc(int $width = 0): string
139139
{
@@ -146,7 +146,7 @@ public function getSrc(int $width = 0): string
146146
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
147147
* srcsets
148148
*
149-
* @return \Twig_Markup|null
149+
* @return \Twig\Markup|null
150150
*/
151151
public function srcset(bool $dpr = false): string
152152
{
@@ -171,7 +171,7 @@ public function getSrcset(bool $dpr = false): string
171171
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
172172
* srcsets
173173
*
174-
* @return \Twig_Markup|null
174+
* @return \Twig\Markup|null
175175
*/
176176
public function srcsetWidth(int $width, bool $dpr = false): string
177177
{
@@ -188,7 +188,7 @@ public function srcsetWidth(int $width, bool $dpr = false): string
188188
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
189189
* srcsets
190190
*
191-
* @return \Twig_Markup|null
191+
* @return \Twig\Markup|null
192192
*/
193193
public function srcsetMinWidth(int $width, bool $dpr = false): string
194194
{
@@ -204,7 +204,7 @@ public function srcsetMinWidth(int $width, bool $dpr = false): string
204204
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
205205
* srcsets
206206
*
207-
* @return \Twig_Markup|null
207+
* @return \Twig\Markup|null
208208
*/
209209
public function srcsetMaxWidth(int $width, bool $dpr = false): string
210210
{
@@ -219,7 +219,7 @@ public function srcsetMaxWidth(int $width, bool $dpr = false): string
219219
*
220220
* @param int $width
221221
*
222-
* @return \Twig_Markup|null
222+
* @return \Twig\Markup|null
223223
*/
224224
public function srcWebp(int $width = 0): string
225225
{
@@ -248,7 +248,7 @@ public function getSrcWebp(int $width = 0): string
248248
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
249249
* srcsets
250250
*
251-
* @return \Twig_Markup|null
251+
* @return \Twig\Markup|null
252252
*/
253253
public function srcsetWebp(bool $dpr = false): string
254254
{
@@ -274,7 +274,7 @@ public function getSrcsetWebp(bool $dpr = false): string
274274
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
275275
* srcsets
276276
*
277-
* @return \Twig_Markup|null
277+
* @return \Twig\Markup|null
278278
*/
279279
public function srcsetWidthWebp(int $width, bool $dpr = false): string
280280
{
@@ -291,7 +291,7 @@ public function srcsetWidthWebp(int $width, bool $dpr = false): string
291291
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
292292
* srcsets
293293
*
294-
* @return \Twig_Markup|null
294+
* @return \Twig\Markup|null
295295
*/
296296
public function srcsetMinWidthWebp(int $width, bool $dpr = false): string
297297
{
@@ -308,7 +308,7 @@ public function srcsetMinWidthWebp(int $width, bool $dpr = false): string
308308
* @param bool $dpr Whether to generate 1x, 2x srcsets vs the normal XXXw
309309
* srcsets
310310
*
311-
* @return \Twig_Markup|null
311+
* @return \Twig\Markup|null
312312
*/
313313
public function srcsetMaxWidthWebp(int $width, bool $dpr = false): string
314314
{
@@ -351,7 +351,7 @@ public function getMaxSrcsetWidth(): int
351351
/**
352352
* Return a base64-encoded placeholder image
353353
*
354-
* @return \Twig_Markup|null
354+
* @return \Twig\Markup|null
355355
*/
356356
public function placeholderImage()
357357
{
@@ -392,7 +392,7 @@ public function placeholderImageSize(): string
392392
*
393393
* @param string|null $color
394394
*
395-
* @return \Twig_Markup|null
395+
* @return \Twig\Markup|null
396396
*/
397397
public function placeholderBox(string $color = null)
398398
{
@@ -429,7 +429,7 @@ public function placeholderBoxSize(): string
429429
/**
430430
* Return a silhouette of the image as an SVG placeholder
431431
*
432-
* @return \Twig_Markup|null
432+
* @return \Twig\Markup|null
433433
*/
434434
public function placeholderSilhouette()
435435
{
@@ -582,9 +582,9 @@ protected function getSrcsetFromArray(array $array, bool $dpr = false): string
582582
/**
583583
* Return a default placeholder image
584584
*
585-
* @return \Twig_Markup
585+
* @return \Twig\Markup
586586
*/
587-
protected function defaultPlaceholderImage(): \Twig_Markup
587+
protected function defaultPlaceholderImage(): \Twig\Markup
588588
{
589589
$width = 1;
590590
$height = 1;

src/models/Settings.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010

1111
namespace nystudio107\imageoptimize\models;
1212

13+
use nystudio107\imageoptimize\ImageOptimize;
1314
use nystudio107\imageoptimize\imagetransforms\CraftImageTransform;
1415
use nystudio107\imageoptimize\imagetransforms\ImageTransformInterface;
1516
use nystudio107\imageoptimize\imagetransforms\ImgixImageTransform;
1617
use nystudio107\imageoptimize\imagetransforms\ThumborImageTransform;
1718

1819
use craft\base\Model;
20+
use craft\behaviors\EnvAttributeParserBehavior;
1921
use craft\validators\ArrayValidator;
2022

23+
use yii\behaviors\AttributeTypecastBehavior;
24+
2125
/**
2226
* ImageOptimize Settings model
2327
*
@@ -362,4 +366,29 @@ public function fields()
362366

363367
return $fields;
364368
}
369+
370+
/**
371+
* @return array
372+
*/
373+
public function behaviors()
374+
{
375+
$craft31Behaviors = [];
376+
if (ImageOptimize::$craft31) {
377+
$craft31Behaviors = [
378+
'parser' => [
379+
'class' => EnvAttributeParserBehavior::class,
380+
'attributes' => [
381+
],
382+
]
383+
];
384+
}
385+
386+
return array_merge($craft31Behaviors, [
387+
'typecast' => [
388+
'class' => AttributeTypecastBehavior::class,
389+
// 'attributeTypes' will be composed automatically according to `rules()`
390+
],
391+
]);
392+
}
393+
365394
}

src/variables/ManifestVariable.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public function __construct()
6060
* @param bool $async
6161
* @param null|array $config
6262
*
63-
* @return \Twig_Markup
63+
* @return \Twig\Markup
6464
* @throws \yii\web\NotFoundHttpException
6565
*/
66-
public function includeCssModule(string $moduleName, bool $async = false, $config = null): \Twig_Markup
66+
public function includeCssModule(string $moduleName, bool $async = false, $config = null): \Twig\Markup
6767
{
6868
return Template::raw(
6969
ManifestHelper::getCssModuleTags(self::$config, $moduleName, $async)
@@ -75,9 +75,9 @@ public function includeCssModule(string $moduleName, bool $async = false, $confi
7575
*
7676
* @param string $path
7777
*
78-
* @return \Twig_Markup
78+
* @return \Twig\Markup
7979
*/
80-
public function includeInlineCssTags(string $path): \Twig_Markup
80+
public function includeInlineCssTags(string $path): \Twig\Markup
8181
{
8282
return Template::raw(
8383
ManifestHelper::getCssInlineTags($path)
@@ -88,9 +88,9 @@ public function includeInlineCssTags(string $path): \Twig_Markup
8888
* Returns the uglified loadCSS rel=preload Polyfill as per:
8989
* https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
9090
*
91-
* @return \Twig_Markup
91+
* @return \Twig\Markup
9292
*/
93-
public static function includeCssRelPreloadPolyfill(): \Twig_Markup
93+
public static function includeCssRelPreloadPolyfill(): \Twig\Markup
9494
{
9595
return Template::raw(
9696
ManifestHelper::getCssRelPreloadPolyfill()
@@ -102,7 +102,7 @@ public static function includeCssRelPreloadPolyfill(): \Twig_Markup
102102
* @param bool $async
103103
* @param null|array $config
104104
*
105-
* @return null|\Twig_Markup
105+
* @return null|\Twig\Markup
106106
* @throws \yii\web\NotFoundHttpException
107107
*/
108108
public function includeJsModule(string $moduleName, bool $async = false, $config = null)
@@ -119,7 +119,7 @@ public function includeJsModule(string $moduleName, bool $async = false, $config
119119
* @param string $type
120120
* @param null $config
121121
*
122-
* @return null|\Twig_Markup
122+
* @return null|\Twig\Markup
123123
* @throws \yii\web\NotFoundHttpException
124124
*/
125125
public function getModuleUri(string $moduleName, string $type = 'modern', $config = null)
@@ -132,9 +132,9 @@ public function getModuleUri(string $moduleName, string $type = 'modern', $confi
132132
/**
133133
* Include the Safari 10.1 nomodule fix JavaScript
134134
*
135-
* @return \Twig_Markup
135+
* @return \Twig\Markup
136136
*/
137-
public function includeSafariNomoduleFix(): \Twig_Markup
137+
public function includeSafariNomoduleFix(): \Twig\Markup
138138
{
139139
return Template::raw(
140140
ManifestHelper::getSafariNomoduleFix()
@@ -146,9 +146,9 @@ public function includeSafariNomoduleFix(): \Twig_Markup
146146
*
147147
* @param string $path
148148
*
149-
* @return \Twig_Markup
149+
* @return \Twig\Markup
150150
*/
151-
public function includeFile(string $path): \Twig_Markup
151+
public function includeFile(string $path): \Twig\Markup
152152
{
153153
return Template::raw(
154154
ManifestHelper::getFile($path)
@@ -162,9 +162,9 @@ public function includeFile(string $path): \Twig_Markup
162162
* @param string $type
163163
* @param null $config
164164
*
165-
* @return \Twig_Markup
165+
* @return \Twig\Markup
166166
*/
167-
public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): \Twig_Markup
167+
public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): \Twig\Markup
168168
{
169169
return Template::raw(
170170
ManifestHelper::getFileFromManifest($config, $fileName, $type)

0 commit comments

Comments
 (0)