Skip to content

Commit

Permalink
Fix isJsonObject error for 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Sep 23, 2020
1 parent 4c9c437 commit d136e8a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/fields/formfields/Recipients.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public static function getSvgIconPath(): string
return 'formie/_formfields/recipients/icon.svg';
}

/**
* Returns whether a string value looks like a JSON object or array.
* TODO: Remove this when bumping to 3.5+
*/
public static function isJsonObject(string $str): bool
{
return (bool)preg_match('/^(?:\{.*\}|\[.*\])$/s', $str);
}


// Public Methods
// =========================================================================
Expand All @@ -69,7 +78,7 @@ public function getIsFieldset(): bool
public function normalizeValue($value, ElementInterface $element = null)
{
// Sort out multiple options being set
if (is_string($value) && Json::isJsonObject($value)) {
if (is_string($value) && self::isJsonObject($value)) {
$value = implode(',', array_filter(Json::decode($value)));
}

Expand Down Expand Up @@ -281,7 +290,7 @@ private function _getRealValue($value)
$value = StringHelper::decdec($value);

// Check if this was an array of data
if (is_string($value) && Json::isJsonObject($value)) {
if (is_string($value) && self::isJsonObject($value)) {
$value = implode(',', array_filter(Json::decode($value)));
}
}
Expand Down

0 comments on commit d136e8a

Please sign in to comment.