Skip to content

Commit

Permalink
Fixed usage of clone action in child admins
Browse files Browse the repository at this point in the history
  • Loading branch information
jorrit committed Aug 27, 2020
1 parent 551e547 commit bc36518
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Controller/CloneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ public function __invoke(Request $request)

$controllerName = $admin->getBaseControllerName();

return $this->forward(
$controllerName.'::createAction',
[
'_sonata_admin' => $request->attributes->get('_sonata_admin'),
CloneAdminExtension::REQUEST_ATTRIBUTE => $subject,
]
);
$routeParameters = [
'_sonata_admin' => $request->attributes->get('_sonata_admin'),
CloneAdminExtension::REQUEST_ATTRIBUTE => $subject,
];

// Copy ids of parents.
for ($currentAdmin = $admin; $currentAdmin->isChild(); ) {
$currentAdmin = $currentAdmin->getParent();
$idParameter = $currentAdmin->getIdParameter();
$routeParameters[$idParameter] = $request->attributes->get($idParameter);
}

return $this->forward($controllerName.'::createAction', $routeParameters);
}
}

0 comments on commit bc36518

Please sign in to comment.