From 4933003b886ed249a08e53306846a21e3211f9e4 Mon Sep 17 00:00:00 2001 From: Alexej Kloos Date: Mon, 5 Jul 2021 16:56:28 +0200 Subject: [PATCH] * Fix graphql query (String cannot represent value). --- .craftplugin | 2 +- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/fields/JasonField.php | 20 ++++++++------------ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.craftplugin b/.craftplugin index 8c50b18..22be5b2 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1 +1 @@ -{"pluginName":"Jason","pluginDescription":"A field type for displaying & editing JSON data.","pluginVersion":"2.0.0","pluginAuthorName":"Chase Giunta","pluginVendorName":"chasegiunta","pluginAuthorUrl":"https://chasegiunta.com","pluginAuthorGithub":"chasegiunta","codeComments":"yes","pluginComponents":["fieldtypes"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} \ No newline at end of file +{"pluginName":"Jason","pluginDescription":"A field type for displaying & editing JSON data.","pluginVersion":"2.0.2","pluginAuthorName":"Chase Giunta","pluginVendorName":"chasegiunta","pluginAuthorUrl":"https://chasegiunta.com","pluginAuthorGithub":"chasegiunta","codeComments":"yes","pluginComponents":["fieldtypes"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} diff --git a/CHANGELOG.md b/CHANGELOG.md index 54cf03f..44800ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 2.0.2 - 2021-06-05 + +### Fixed + +- Fix graphql query (String cannot represent value). + ## 2.0.1 - 2020-05-11 ### Fixed diff --git a/composer.json b/composer.json index ae2b0d7..24a3e53 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "chasegiunta/craft-jason", "description": "A field type for displaying & editing JSON data.", "type": "craft-plugin", - "version": "2.0.1", + "version": "2.0.2", "keywords": [ "craft", "cms", diff --git a/src/fields/JasonField.php b/src/fields/JasonField.php index b01d582..b360173 100644 --- a/src/fields/JasonField.php +++ b/src/fields/JasonField.php @@ -59,7 +59,7 @@ class JasonField extends Field */ public static function displayName(): string { - return 'JSON (Jason)'; + return 'JSON (Jason)'; } // Public Methods @@ -123,11 +123,7 @@ public function getContentColumnType(): string */ public function normalizeValue($value, ElementInterface $element = null) { - if (Craft::$app->request->getIsSiteRequest() && !Craft::$app->request->getIsActionRequest()) { - return json_decode($value, true); - } else { - return $value; - } + return parent::normalizeValue($value, $element); } /** @@ -243,8 +239,8 @@ public function serializeValue($value, ElementInterface $element = null) public function getSettingsHtml() { // Register our asset bundle - Craft::$app->getView()->registerAssetBundle(JasonFieldAsset::class, View::POS_BEGIN ); - + Craft::$app->getView()->registerAssetBundle(JasonFieldAsset::class, View::POS_BEGIN); + $id = Craft::$app->getView()->formatInputId('jason'); $namespacedId = Craft::$app->getView()->namespaceInputId($id); @@ -364,7 +360,7 @@ public function getInputHtml($value, ElementInterface $element = null): string $valid = true; } else { // Assume we're accessing from control panel - $json = json_decode($value); + $json = json_decode($value); if ($json === null) { $json = $value; $valid = false; @@ -420,11 +416,11 @@ public function getElementValidationRules(): array public function validateIsJSON(ElementInterface $element, array $params = null) { $value = $element->getFieldValue($this->handle); - - $json = json_decode($value); + + $json = json_decode($value); if ($json === null) { - // JSON cannot be decoded + // JSON cannot be decoded $element->addError($this->handle, Craft::t('site', 'Not valid JSON.')); } }