From fee695e7b8c24e06fe9bb3f243925d796e80e73d Mon Sep 17 00:00:00 2001 From: sukhwinder-somar Date: Wed, 11 Oct 2023 00:20:11 +1300 Subject: [PATCH] fix form submission, when form block is inside another block --- .../ElementalContentControllerExtension.php | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Extensions/ElementalContentControllerExtension.php b/src/Extensions/ElementalContentControllerExtension.php index 243aa2b4..90adae2a 100644 --- a/src/Extensions/ElementalContentControllerExtension.php +++ b/src/Extensions/ElementalContentControllerExtension.php @@ -35,9 +35,7 @@ public function handleElement() } foreach ($elementalAreaRelations as $elementalAreaRelation) { - $element = $elementOwner->$elementalAreaRelation()->Elements() - ->filter('ID', $id) - ->First(); + $element = $this->findElement($elementOwner->{$elementalAreaRelation}()->Elements(), $id); if ($element) { return $element->getController(); @@ -47,4 +45,35 @@ public function handleElement() user_error('Element $id not found for this page', E_USER_ERROR); return false; } + + private function findElement($elements, $id) + { + $element = $elements->filter('ID', $id)->First(); + + if ($element) { + return $element; + } + + foreach ($elements as $el) { + if (!$el->hasMethod('Elements')) { + continue; + } + + $subElementAreaRelations = $el->getElementalRelations(); + + if (!$subElementAreaRelations) { + continue; + } + + foreach ($subElementAreaRelations as $subElementalAreaRelation) { + $element = $this->findElement($el->{$subElementalAreaRelation}()->Elements(), $id); + + if ($element) { + return $element; + } + } + } + + return null; + } }