Skip to content

Commit

Permalink
IBX-8485: Redirect after creating location should point to referer lo…
Browse files Browse the repository at this point in the history
…cation (#1287)

* IBX-8485: Redirect after creating location should point to referer location

* IBX-8485: Applied review remarks
  • Loading branch information
barw4 authored Jul 16, 2024
1 parent 59bad30 commit a8ad564
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/bundle/Controller/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,28 +488,38 @@ public function addAction(Request $request): Response

$contentInfo = $form->getData()->getContentInfo();

if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (ContentLocationAddData $data) {
$contentInfo = $data->getContentInfo();
$referer = $request->headers->get('Referer');

foreach ($data->getNewLocations() as $newLocation) {
$locationCreateStruct = $this->locationService->newLocationCreateStruct($newLocation->id);
$this->locationService->createLocation($contentInfo, $locationCreateStruct);

$this->notificationHandler->success(
/** @Desc("Location '%name%' created.") */
'location.create.success',
['%name%' => $newLocation->getContentInfo()->name],
'ibexa_location'
if ($form->isSubmitted()) {
$result = $this->submitHandler->handle(
$form,
function (ContentLocationAddData $data) use ($referer): RedirectResponse {
$contentInfo = $data->getContentInfo();

foreach ($data->getNewLocations() as $newLocation) {
$locationCreateStruct = $this->locationService->newLocationCreateStruct($newLocation->id);
$this->locationService->createLocation($contentInfo, $locationCreateStruct);

$this->notificationHandler->success(
/** @Desc("Location '%name%' created.") */
'location.create.success',
['%name%' => $newLocation->getContentInfo()->name],
'ibexa_location',
);
}

$redirectUrl = $referer ?: $this->generateUrl(
'ibexa.content.view',
[
'contentId' => $contentInfo->id,
'locationId' => $contentInfo->mainLocationId,
'_fragment' => LocationsTab::URI_FRAGMENT,
],
);
}

return new RedirectResponse($this->generateUrl('ibexa.content.view', [
'contentId' => $contentInfo->id,
'locationId' => $contentInfo->mainLocationId,
'_fragment' => LocationsTab::URI_FRAGMENT,
]));
});
return new RedirectResponse($redirectUrl);
}
);

if ($result instanceof Response) {
return $result;
Expand Down

0 comments on commit a8ad564

Please sign in to comment.