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 non-json strings issue #46

Merged
merged 3 commits into from
Jan 11, 2019
Merged
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
8 changes: 5 additions & 3 deletions src/fields/LinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ public function normalizeValue($value, ElementInterface $element = null) {

if (is_string($value)) {
// If value is a string we are loading the data from the database
$attr += Json::decode($value, true);

try {
$attr += Json::decode($value, true);
} catch (\Exception $e) {}

} else if (is_array($value) && isset($value['isCpFormData'])) {
// If it is an array and the field `isCpFormData` is set, we are saving a cp form
$attr += [
Expand All @@ -128,7 +130,7 @@ public function normalizeValue($value, ElementInterface $element = null) {
'value' => $this->getLinkValue($value)
];

} elseif (is_array($value)) {
} else if (is_array($value)) {
// Finally, if it is an array it is a serialized value
$attr = [
'owner' => $element,
Expand Down