Skip to content

Commit

Permalink
refactor: Decode JSON just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jun 13, 2024
1 parent 4810f55 commit da2c824
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/fields/ShortLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use craft\base\InlineEditableFieldInterface;
use craft\base\PreviewableFieldInterface;
use craft\helpers\ElementHelper;
use craft\helpers\Json;
use craft\helpers\UrlHelper;
use nystudio107\retour\Retour as RetourPlugin;
use yii\helpers\StringHelper;
Expand Down Expand Up @@ -102,6 +103,10 @@ public function getSettingsHtml(): string
*/
public function getPreviewHtml($value, ElementInterface $element): string
{
$decoded = Json::decodeIfJson($value);
if (is_array($decoded)) {
$value = $decoded['legacyUrl'] ?? '';
}
// Render the preview template
return Craft::$app->getView()->renderTemplate(
'retour/_components/fields/ShortLink_preview',
Expand Down

0 comments on commit da2c824

Please sign in to comment.