Skip to content

Commit

Permalink
fix form submission, when form block is inside another block
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder-somar committed Oct 10, 2023
1 parent 9073dae commit fee695e
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/Extensions/ElementalContentControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
}

0 comments on commit fee695e

Please sign in to comment.