From 4484edd9fe74a9fa69de9f222a3bb55212f2d5b8 Mon Sep 17 00:00:00 2001 From: Marion Newlevant Date: Tue, 22 Dec 2020 23:15:25 -0800 Subject: [PATCH] Version 1.0.3 - tolerate Embedded Assets plugin not installed --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/services/EmbeddedAssetsLinkService.php | 13 ++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0346d46..3d6f6eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Embedded Assets Link Changelog +## 1.0.3 - 2020-12-22 +### Fixed +- No error when Embedded Assets plugin not installed + ## 1.0.2 - 2020-11-02 ### Fixed - finished renaming from v 1.0.1 diff --git a/composer.json b/composer.json index 2313ff5..eff4717 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "marionnewlevant/embedded-assets-link", "description": "Adds a link to the Embedded Asset in the Control Panel", "type": "craft-plugin", - "version": "1.0.2", + "version": "1.0.3", "keywords": [ "craft", "cms", diff --git a/src/services/EmbeddedAssetsLinkService.php b/src/services/EmbeddedAssetsLinkService.php index b690a6d..98f7c9e 100644 --- a/src/services/EmbeddedAssetsLinkService.php +++ b/src/services/EmbeddedAssetsLinkService.php @@ -32,12 +32,15 @@ class EmbeddedAssetsLinkService extends Component */ public function assetUrl(int $elementId, string $elementType, int $siteId) { - $element = Craft::$app->elements->getElementById($elementId, $elementType, $siteId); - - $embeddedAsset = EmbeddedAssets::$plugin->methods->getEmbeddedAsset($element); - if ($embeddedAsset) + if (EmbeddedAssets::$plugin) // will be null if embedded assets plugin not installed. { - return $embeddedAsset->url; + $element = Craft::$app->elements->getElementById($elementId, $elementType, $siteId); + + $embeddedAsset = EmbeddedAssets::$plugin->methods->getEmbeddedAsset($element); + if ($embeddedAsset) + { + return $embeddedAsset->url; + } } return null;