Skip to content

Commit 2b94f4b

Browse files
author
Andrew Welch
committed
Merge branch 'release/1.6.43' into v1
2 parents d82326e + 2ce686d commit 2b94f4b

File tree

3 files changed

+92
-85
lines changed

3 files changed

+92
-85
lines changed

CHANGELOG.md

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

3+
## 1.6.43 - 2022.03.14
4+
5+
### Fixed
6+
7+
* Fixed an issue where an exception could be thrown when running the `craft resave/assets` console command ([#78](https://github.com/nystudio107/craft-imageoptimize/issues/78))
8+
39
## 1.6.42 - 2022.02.23
410

511
### Added

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.6.42",
5+
"version": "1.6.43",
66
"keywords": [
77
"craft",
88
"cms",

src/fields/OptimizedImages.php

Lines changed: 85 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ public function afterElementSave(ElementInterface $asset, bool $isNew)
240240
* itself is being updated (via the ImageEditor). If so, update the
241241
* variants immediately so the AssetSelectorHud displays the new images
242242
*/
243-
if (Craft::$app->getRequest()->getPathInfo() === 'actions/assets/save-image') {
243+
$request = Craft::$app->getRequest();
244+
if (!$request->isConsoleRequest && $request->getPathInfo() === 'actions/assets/save-image') {
244245
try {
245246
ImageOptimize::$plugin->optimizedImages->updateOptimizedImageFieldData($this, $asset);
246247
} catch (Exception $e) {
@@ -373,6 +374,89 @@ public function getSettingsHtml()
373374
return '';
374375
}
375376

377+
/**
378+
* @inheritdoc
379+
*/
380+
public function getInputHtml($value, ElementInterface $element = null): string
381+
{
382+
if ($element !== null && $element instanceof Asset && $this->handle !== null) {
383+
/** @var Asset $element */
384+
// Register our asset bundle
385+
try {
386+
Craft::$app->getView()->registerAssetBundle(ImageOptimizeAsset::class);
387+
} catch (InvalidConfigException $e) {
388+
Craft::error($e->getMessage(), __METHOD__);
389+
}
390+
391+
// Get our id and namespace
392+
if (ImageOptimize::$craft35) {
393+
$id = Html::id($this->handle);
394+
} else {
395+
$id = Craft::$app->getView()->formatInputId($this->handle);
396+
}
397+
$nameSpaceId = Craft::$app->getView()->namespaceInputId($id);
398+
399+
// Variables to pass down to our field JavaScript to let it namespace properly
400+
$jsonVars = [
401+
'id' => $id,
402+
'name' => $this->handle,
403+
'namespace' => $nameSpaceId,
404+
'prefix' => Craft::$app->getView()->namespaceInputId(''),
405+
];
406+
$jsonVars = Json::encode($jsonVars);
407+
$view = Craft::$app->getView();
408+
$view->registerJs(
409+
"$('#{$nameSpaceId}-field').ImageOptimizeOptimizedImages(" .
410+
$jsonVars .
411+
");"
412+
);
413+
414+
$settings = ImageOptimize::$plugin->getSettings();
415+
$createVariants = ImageOptimize::$plugin->optimizedImages->shouldCreateVariants($this, $element);
416+
417+
// Render the input template
418+
try {
419+
return Craft::$app->getView()->renderTemplate(
420+
'image-optimize/_components/fields/OptimizedImages_input',
421+
[
422+
'name' => $this->handle,
423+
'value' => $value,
424+
'variants' => $this->variants,
425+
'field' => $this,
426+
'settings' => $settings,
427+
'elementId' => $element->id,
428+
'format' => $element->getExtension(),
429+
'id' => $id,
430+
'nameSpaceId' => $nameSpaceId,
431+
'createVariants' => $createVariants,
432+
]
433+
);
434+
} catch (LoaderError $e) {
435+
Craft::error($e->getMessage(), __METHOD__);
436+
} catch (\yii\base\Exception $e) {
437+
Craft::error($e->getMessage(), __METHOD__);
438+
}
439+
}
440+
441+
// Render an error template, since the field only works when attached to an Asset
442+
try {
443+
return Craft::$app->getView()->renderTemplate(
444+
'image-optimize/_components/fields/OptimizedImages_error',
445+
[
446+
]
447+
);
448+
} catch (LoaderError $e) {
449+
Craft::error($e->getMessage(), __METHOD__);
450+
} catch (\yii\base\Exception $e) {
451+
Craft::error($e->getMessage(), __METHOD__);
452+
}
453+
454+
return '';
455+
}
456+
457+
// Protected Methods
458+
// =========================================================================
459+
376460
/**
377461
* Returns an array of asset volumes and their sub-folders
378462
*
@@ -409,9 +493,6 @@ protected function getFieldVolumeInfo($fieldHandle): array
409493
return $result;
410494
}
411495

412-
// Protected Methods
413-
// =========================================================================
414-
415496
/**
416497
* See if the passed $volume has an OptimizedImagesField with the handle $fieldHandle
417498
*
@@ -461,84 +542,4 @@ protected function assembleSourceList(array $folders, bool $includeNestedFolders
461542

462543
return $sources;
463544
}
464-
465-
/**
466-
* @inheritdoc
467-
*/
468-
public function getInputHtml($value, ElementInterface $element = null): string
469-
{
470-
if ($element !== null && $element instanceof Asset && $this->handle !== null) {
471-
/** @var Asset $element */
472-
// Register our asset bundle
473-
try {
474-
Craft::$app->getView()->registerAssetBundle(ImageOptimizeAsset::class);
475-
} catch (InvalidConfigException $e) {
476-
Craft::error($e->getMessage(), __METHOD__);
477-
}
478-
479-
// Get our id and namespace
480-
if (ImageOptimize::$craft35) {
481-
$id = Html::id($this->handle);
482-
} else {
483-
$id = Craft::$app->getView()->formatInputId($this->handle);
484-
}
485-
$nameSpaceId = Craft::$app->getView()->namespaceInputId($id);
486-
487-
// Variables to pass down to our field JavaScript to let it namespace properly
488-
$jsonVars = [
489-
'id' => $id,
490-
'name' => $this->handle,
491-
'namespace' => $nameSpaceId,
492-
'prefix' => Craft::$app->getView()->namespaceInputId(''),
493-
];
494-
$jsonVars = Json::encode($jsonVars);
495-
$view = Craft::$app->getView();
496-
$view->registerJs(
497-
"$('#{$nameSpaceId}-field').ImageOptimizeOptimizedImages(" .
498-
$jsonVars .
499-
");"
500-
);
501-
502-
$settings = ImageOptimize::$plugin->getSettings();
503-
$createVariants = ImageOptimize::$plugin->optimizedImages->shouldCreateVariants($this, $element);
504-
505-
// Render the input template
506-
try {
507-
return Craft::$app->getView()->renderTemplate(
508-
'image-optimize/_components/fields/OptimizedImages_input',
509-
[
510-
'name' => $this->handle,
511-
'value' => $value,
512-
'variants' => $this->variants,
513-
'field' => $this,
514-
'settings' => $settings,
515-
'elementId' => $element->id,
516-
'format' => $element->getExtension(),
517-
'id' => $id,
518-
'nameSpaceId' => $nameSpaceId,
519-
'createVariants' => $createVariants,
520-
]
521-
);
522-
} catch (LoaderError $e) {
523-
Craft::error($e->getMessage(), __METHOD__);
524-
} catch (\yii\base\Exception $e) {
525-
Craft::error($e->getMessage(), __METHOD__);
526-
}
527-
}
528-
529-
// Render an error template, since the field only works when attached to an Asset
530-
try {
531-
return Craft::$app->getView()->renderTemplate(
532-
'image-optimize/_components/fields/OptimizedImages_error',
533-
[
534-
]
535-
);
536-
} catch (LoaderError $e) {
537-
Craft::error($e->getMessage(), __METHOD__);
538-
} catch (\yii\base\Exception $e) {
539-
Craft::error($e->getMessage(), __METHOD__);
540-
}
541-
542-
return '';
543-
}
544545
}

0 commit comments

Comments
 (0)