Skip to content

Commit

Permalink
Add redirect to View before Edit upon deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
machacekmartin authored Feb 8, 2024
1 parent 2df77df commit f3d12b5
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/Pages/NestedEditRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ protected function configureDeleteAction(DeleteAction $action): void

$ancestorResource = $ancestor->getResource();

$urlParameters = $ancestor->getNormalizedRouteParameters($this->getRecord());

$redirectUrl = match (true) {
$resource::hasPage('index') => $resource::getUrl('index', $urlParameters),
$ancestorResource::hasPage('view') => $ancestorResource::getUrl('view', $urlParameters),
default => $ancestorResource::getUrl('edit', $urlParameters),
};

$action
->authorize($resource::canDelete($this->getRecord()))
->successRedirectUrl(
$resource::hasPage('index')
? $resource::getUrl('index', [
...$ancestor->getNormalizedRouteParameters($this->getRecord()),
])
: $ancestorResource::getUrl('edit', [
...$ancestor->getNormalizedRouteParameters($this->getRecord()),
])
)
;
->successRedirectUrl($redirectUrl);
}

protected function configureForceDeleteAction(ForceDeleteAction $action): void
Expand All @@ -54,18 +53,17 @@ protected function configureForceDeleteAction(ForceDeleteAction $action): void

$ancestorResource = $ancestor->getResource();

$urlParameters = $ancestor->getNormalizedRouteParameters($this->getRecord());

$redirectUrl = match (true) {
$resource::hasPage('index') => $resource::getUrl('index', $urlParameters),
$ancestorResource::hasPage('view') => $ancestorResource::getUrl('view', $urlParameters),
default => $ancestorResource::getUrl('edit', $urlParameters),
};

$action
->authorize($resource::canForceDelete($this->getRecord()))
->successRedirectUrl(
$resource::hasPage('index')
? $resource::getUrl('index', [
...$ancestor->getNormalizedRouteParameters($this->getRecord()),
])
: $ancestorResource::getUrl('edit', [
...$ancestor->getNormalizedRouteParameters($this->getRecord()),
])
)
;
->successRedirectUrl($redirectUrl);
}

protected function configureViewAction(ViewAction $action): void
Expand Down

0 comments on commit f3d12b5

Please sign in to comment.