From e85cb2fcb0303ab73c5232194403d9fe66abecbb Mon Sep 17 00:00:00 2001 From: Lindsey DiLoreto Date: Tue, 1 Oct 2024 15:45:37 -0700 Subject: [PATCH] Fixed bug when using pre-defined image transforms --- CHANGELOG.md | 5 +++++ src/models/Config.php | 38 +++++++++++++++----------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 089aa3a..f3638b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +### Fixed +- Fixed bug encountered when using pre-defined image transforms. ([#43](https://github.com/doublesecretagency/craft-adwizard/issues/43)) + ## 3.4.0 - 2024-05-29 ### Added diff --git a/src/models/Config.php b/src/models/Config.php index 758802f..e2cd455 100644 --- a/src/models/Config.php +++ b/src/models/Config.php @@ -147,35 +147,27 @@ private function _parseJs(): void /** * Process transform * - * @throws NotFoundHttpException * @throws InvalidConfigException + * @throws NotFoundHttpException */ private function _parseTransform(): void { - if (is_string($this->image['transform'])) { - - // Get pre-defined transform - $transform = clone Craft::$app->getAssetTransforms()->getTransformByHandle($this->image['transform']); - - if (!$transform) { - throw new NotFoundHttpException('Transform not found'); + // If a transform was specified + if ($this->image['transform']) { + + // If transform is a string + if (is_string($this->image['transform'])) { + // Get pre-defined transform + $transform = $this->image['transform']; + // Else if transform is an array + } else if (is_array($this->image['transform'])) { + // Get dynamic transform + $transform = new ImageTransform($this->image['transform']); + } else { + // Invalid transform + throw new NotFoundHttpException('Invalid transform format, please use a string or array.'); } - } else if (is_array($this->image['transform']) && !empty($this->image['transform'])) { - - // Get dynamic transform - $transform = new ImageTransform($this->image['transform']); - - } else { - - // No transform - $transform = false; - - } - - // If transform exists - if ($transform) { - // Apply transform $url = $this->asset->getUrl($transform); $width = $this->asset->getWidth($transform);