diff --git a/CHANGELOG.md b/CHANGELOG.md index 691f9be..5ed6d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,19 @@ 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.0-rc2 - 2021.02.17 +## 2.0.0-rc3 - 2021.08.16 + +### Fixes +- Fixes issues with telephone not saving under some circumstances -> v2.0.0 requires `"oembed/oembed": "^4.0"` which requires `"php": "^7.4|^8",`. Additionally the return data format has changed due to the updated `oembed/oembed` library. The new format can be found in the [https://github.com/newism/craft3-fields/blob/master/README.md](README.md). Existing content will still continue to work. +## 2.0.0-rc2 - 2021.02.17 ### Fixes - `{{ entry.embedField.embedData.code }}` is now an array. Use `{{ entry.embedField.embedData.code.html }}` to get the value ## 2.0.0-rc1 - 2021.02.16 -> v2.0.0 requires `"oembed/oembed": "^4.0"` which requires `"php": "^7.4|^8",`. Additionally the return data format has changed due to the updated `oembed/oembed` library. The new format can be found in the [https://github.com/newism/craft3-fields/blob/master/README.md](README.md). Existing content will still continue to work. +> {warning} v2.0.0 requires `"oembed/oembed": "^4.0"` which requires `"php": "^7.4|^8",`. Additionally the return data format has changed due to the updated `oembed/oembed` library. The new format can be found in the [https://github.com/newism/craft3-fields/blob/master/README.md](README.md). Existing content will still continue to work. ### Changes - Updated dependency on `oembed/oembed` to ^v4.0 diff --git a/src/fields/Embed.php b/src/fields/Embed.php index 5e6ebbd..4cb26fa 100644 --- a/src/fields/Embed.php +++ b/src/fields/Embed.php @@ -102,10 +102,23 @@ public function rules(): array */ public function normalizeValue($value, ElementInterface $element = null) { + /** + * Just return value if it's already an EmbedModel. + */ + if ($value instanceof EmbedModel) { + return $value; + } + + /** + * Serialised value from the DB + */ if (is_string($value)) { - $value = json_decode($value, true); + $value = json_decode($value, true, 512, JSON_THROW_ON_ERROR); } + /** + * Array value from post or unserialized array + */ if (is_array($value) && $value['rawInput']) { if (!Craft::$app->getRequest()->getIsConsoleRequest() && Craft::$app->getRequest()->getIsPost()) { $embedData = NsmFields::getInstance()->embed->parse($value['rawInput']); diff --git a/src/fields/Gender.php b/src/fields/Gender.php index ee8ee02..7824994 100644 --- a/src/fields/Gender.php +++ b/src/fields/Gender.php @@ -99,10 +99,23 @@ public function normalizeValue( $value, ElementInterface $element = null ) { + /** + * Just return value if it's already an GenderModel. + */ + if ($value instanceof GenderModel) { + return $value; + } + + /** + * Serialised value from the DB + */ if (is_string($value)) { - $value = json_decode($value, true); + $value = json_decode($value, true, 512, JSON_THROW_ON_ERROR); } + /** + * Array value from post or unserialized array + */ if (is_array($value) && !empty(array_filter($value))) { return new GenderModel($value); } diff --git a/src/fields/PersonName.php b/src/fields/PersonName.php index 0421a34..47c43b0 100644 --- a/src/fields/PersonName.php +++ b/src/fields/PersonName.php @@ -99,10 +99,23 @@ public function normalizeValue( $value, ElementInterface $element = null ) { + /** + * Just return value if it's already an PersonNameModel. + */ + if ($value instanceof PersonNameModel) { + return $value; + } + + /** + * Serialised value from the DB + */ if (is_string($value)) { $value = json_decode($value, true); } + /** + * Array value from post or unserialized array + */ if (is_array($value) && !empty(array_filter($value))) { return new PersonNameModel($value); } diff --git a/src/fields/Telephone.php b/src/fields/Telephone.php index 7b1049c..a871866 100644 --- a/src/fields/Telephone.php +++ b/src/fields/Telephone.php @@ -110,6 +110,13 @@ public function rules(): array */ public function normalizeValue($value, ElementInterface $element = null) { + /** + * Just return value if it's already an TelephoneModel. + */ + if ($value instanceof TelephoneModel) { + return $value; + } + /** * Serialised value from the DB */ @@ -118,16 +125,16 @@ public function normalizeValue($value, ElementInterface $element = null) } /** - * Default values + * Array value from post or unserialized array */ - if (!is_array($value)) { - $value = [ - 'countryCode' => $this->defaultCountryCode, - 'rawInput' => '', - ]; + if (is_array($value) && !empty(array_filter($value))) { + return new TelephoneModel([ + $value['countryCode'] ?? $this->defaultCountryCode, + $value['rawInput'] + ]); } - return new TelephoneModel($value['countryCode'] ?? $this->defaultCountryCode, $value['rawInput']); + return null; } /**