From 79f5895496f19e29d5982cbc9254857d0215fb99 Mon Sep 17 00:00:00 2001 From: Damien MATHIEU Date: Thu, 15 Feb 2024 20:41:36 +0100 Subject: [PATCH 1/3] Allow callable for block config options Allow options for block config to be AJAX-derived options. --- formwidgets/Blocks.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/formwidgets/Blocks.php b/formwidgets/Blocks.php index 6f19375..0d9443d 100644 --- a/formwidgets/Blocks.php +++ b/formwidgets/Blocks.php @@ -337,9 +337,14 @@ protected function processInspectorConfig(array $config): array 'span', ])); - if (isset($defined['options']) && is_array($defined['options'])) { - foreach ($defined['options'] as $key => &$value) { - $value = Lang::get($value); + if (isset($defined['options'])) { + if (is_array($defined['options'])) { + foreach ($defined['options'] as $key => &$value) { + $value = Lang::get($value); + } + } elseif (is_callable($defined['options'])) { + $callable = $defined['options']; + $defined['options'] = $callable($this->formWidget, $this->formField); } } From 26b4fc5673164c1b529b3a7b8a64299681f15556 Mon Sep 17 00:00:00 2001 From: Damien MATHIEU Date: Fri, 16 Feb 2024 12:32:50 +0100 Subject: [PATCH 2/3] Pass field name to callable block config --- formwidgets/Blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formwidgets/Blocks.php b/formwidgets/Blocks.php index 0d9443d..f746ad5 100644 --- a/formwidgets/Blocks.php +++ b/formwidgets/Blocks.php @@ -344,7 +344,7 @@ protected function processInspectorConfig(array $config): array } } elseif (is_callable($defined['options'])) { $callable = $defined['options']; - $defined['options'] = $callable($this->formWidget, $this->formField); + $defined['options'] = $callable($property); } } From 38cd3706a818af5df63967b19653836026328468 Mon Sep 17 00:00:00 2001 From: DamsFX Date: Tue, 11 Feb 2025 18:28:20 +0100 Subject: [PATCH 3/3] Force block config to be return as array fix #23 --- classes/Block.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/classes/Block.php b/classes/Block.php index d3fb086..158318c 100644 --- a/classes/Block.php +++ b/classes/Block.php @@ -9,7 +9,6 @@ use Cms\Classes\Controller; use Cms\Classes\PartialStack; use Illuminate\Support\Facades\Lang; -use Illuminate\Support\Fluent; use Winter\Storm\Exception\SystemException; /** @@ -107,7 +106,7 @@ public static function renderAll(array $blocks, ?Controller $controller = null): $config = static::getDefaultConfig($block['_group']); } - $partialData['config'] = new Fluent($config); + $partialData['config'] = json_decode(json_encode($config), true); $content .= $controller->renderPartial($block['_group'] . '.block', $partialData); }