From 7ab439e54b218757b27f805573a48c2f2db418ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 12 Feb 2024 19:07:07 +0100 Subject: [PATCH] fix infer for cascadefrom --- src/Form/AbstractLayout.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Form/AbstractLayout.php b/src/Form/AbstractLayout.php index a85b9408ba..52bb7adad8 100644 --- a/src/Form/AbstractLayout.php +++ b/src/Form/AbstractLayout.php @@ -49,9 +49,20 @@ public function addControl(string $name, $control = [], array $fieldSeed = []): if (is_a($controlClass, Control\Checkbox::class, true)) { $fieldSeed['type'] = 'boolean'; } elseif (is_a($controlClass, Control\Dropdown::class, true) || is_a($controlClass, Control\Lookup::class, true)) { - $dropdownModel = $control instanceof Control ? $control->model : ($control['model'] ?? null); - if ($dropdownModel !== null) { - $fieldSeed['type'] = $dropdownModel->getField($dropdownModel->idField)->type; + if (is_a($controlClass, Control\DropdownCascade::class, true)) { + $cascadeFromControl = $control instanceof Control ? $control->cascadeFrom : ($control['cascadeFrom'] ?? null); + if ($cascadeFromControl !== null) { + if (!$cascadeFromControl instanceof Control) { + $cascadeFromControl = $this->form->getControl($cascadeFromControl); + } + + $fieldSeed['type'] = $cascadeFromControl->entityField->getField()->type; + } + } else { + $dropdownModel = $control instanceof Control ? $control->model : ($control['model'] ?? null); + if ($dropdownModel !== null) { + $fieldSeed['type'] = $dropdownModel->getField($dropdownModel->idField)->type; + } } } elseif (is_a($controlClass, Control\Calendar::class, true)) { $calendarType = $control instanceof Control\Calendar ? $control->type : ($control['type'] ?? null);