From 79f5895496f19e29d5982cbc9254857d0215fb99 Mon Sep 17 00:00:00 2001 From: Damien MATHIEU Date: Thu, 15 Feb 2024 20:41:36 +0100 Subject: [PATCH 1/2] 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/2] 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); } }