Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Fix graphql query (String cannot represent value) #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -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"}
{"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"}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 8 additions & 12 deletions src/fields/JasonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class JasonField extends Field
*/
public static function displayName(): string
{
return 'JSON (Jason)';
return 'JSON (Jason)';
}

// Public Methods
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.'));
}
}
Expand Down