From d136e8a5e081b86af0cab0d9c260b75addbdde5b Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Wed, 23 Sep 2020 19:41:59 +1000 Subject: [PATCH] Fix `isJsonObject` error for 3.4 --- src/fields/formfields/Recipients.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/fields/formfields/Recipients.php b/src/fields/formfields/Recipients.php index d10bfe9e7..a36f763ff 100644 --- a/src/fields/formfields/Recipients.php +++ b/src/fields/formfields/Recipients.php @@ -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 // ========================================================================= @@ -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))); } @@ -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))); } }