Skip to content

Commit

Permalink
Adjust PhpTek\JSONText\ORM\FieldType\JSONText to supply array when va…
Browse files Browse the repository at this point in the history
…lue is empty
  • Loading branch information
Jackson committed Apr 30, 2018
1 parent 6d49c75 commit b6c7da6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions code/ORM/FieldType/JSONText.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,20 @@ public function toSSTypes(array $data)
*/
public function toArray($value = null)
{
$output = [];
$value = $value ?: $this->getValue();
$decoded = json_decode($value, true);

if (is_null($decoded)) {
$msg = 'Decoded JSON is invalid.';
throw new JSONTextDataException($msg);
// Check for value
if (!empty($value)) {
$output = json_decode($value, true);

// Check for parse errors
if (JSON_ERROR_NONE !== json_last_error()) {
throw new JSONTextDataException('Unable to parse JSONText value into array: ' . json_last_error());
}
}

return $decoded;
return $output;
}

/**
Expand Down

0 comments on commit b6c7da6

Please sign in to comment.