Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix form submission, when form block is inside another block #1107

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}