Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Fix issue with telephone not saving
Browse files Browse the repository at this point in the history
  • Loading branch information
leevigraham committed Aug 16, 2021
1 parent 5d86cff commit b9ae651
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/fields/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
15 changes: 14 additions & 1 deletion src/fields/Gender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions src/fields/PersonName.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
21 changes: 14 additions & 7 deletions src/fields/Telephone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit b9ae651

Please sign in to comment.