From a849e871cc26e6928ad73ba60f28865023881e95 Mon Sep 17 00:00:00 2001 From: matdave Date: Wed, 27 May 2026 15:28:49 -0500 Subject: [PATCH] feat: parse Template Variable options Signed-off-by: matdave --- .../fred/src/Traits/Endpoint/Ajax/LoadContent.php | 4 +++- core/components/fred/src/Utils.php | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/components/fred/src/Traits/Endpoint/Ajax/LoadContent.php b/core/components/fred/src/Traits/Endpoint/Ajax/LoadContent.php index 0553a04e..4cc7c3fa 100644 --- a/core/components/fred/src/Traits/Endpoint/Ajax/LoadContent.php +++ b/core/components/fred/src/Traits/Endpoint/Ajax/LoadContent.php @@ -97,11 +97,13 @@ protected function gatherTVs($resource) ]; if (!empty($props['fred.options'])) { - $def['options'] = json_decode($props['fred.options']); + $v = \Fred\Utils::modxParseString($this->modx, $props['fred.options']); + $def['options'] = json_decode($v); unset($props['fred.options']); } foreach ($props as $k => $v) { if (substr($k, 0, 5) === "fred.") { + $v = \Fred\Utils::modxParseString($this->modx, $v); $def[substr($k, 5)] = $v; } } diff --git a/core/components/fred/src/Utils.php b/core/components/fred/src/Utils.php index 81c8fedd..e2f82e94 100644 --- a/core/components/fred/src/Utils.php +++ b/core/components/fred/src/Utils.php @@ -83,13 +83,18 @@ public static function modxParseString($modx, $data, $phs = []) $data = json_encode($data); } /** @var \MODX\Revolution\modChunk $chunk */ - $chunk = $modx->newObject('modChunk', ['name' => 'inline-' . uniqid()]); + $chunk = $modx->newObject('modChunk', ['name' => 'inline-' . uniqid('', true)]); $chunk->setCacheable(false); $output = $chunk->process($phs, $data); if ($isArray === true) { - $output = json_decode($output, true); + try { + $output = json_decode($output, true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $modx->log(\modX::LOG_LEVEL_ERROR, 'Failed to parse JSON string: ' . $e->getMessage()); + return []; + } } return $output;