Skip to content

Commit

Permalink
fix: add view page redirect before edit fallback
Browse files Browse the repository at this point in the history
Merge pull request #1 from machacekmartin/patch-3: Redirect to View if possible before Edit
  • Loading branch information
machacekmartin authored and lukas-frey committed Feb 19, 2024
2 parents f3d12b5 + 5886640 commit e50393f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/Resources/NestedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,14 @@ public static function getBreadcrumbs(Page $page, ?Model $record = null): array
}

if ($ancestor) {
$index = $resource::hasPage('index')
? [
$resource::getUrl('index', [
...$ancestor->getNormalizedRouteParameters($record ?? $relatedRecord),
]) => $resource::getBreadcrumb(),
]
: [
$ancestor->getResource()::getUrl('edit', [
...$ancestor->getNormalizedRouteParameters($record ?? $relatedRecord),
]) . '#relation-manager' => $resource::getBreadcrumb(),
];
$ancestorResource = $ancestor->getResource();
$urlParameters = $ancestor->getNormalizedRouteParameters($record ?? $relatedRecord);

$index = match (true) {
$resource::hasPage('index') => [$resource::getUrl('index', $urlParameters) => $resource::getBreadcrumb()],
$ancestorResource::hasPage('view') => [$ancestorResource::getUrl('view', $urlParameters) . '#relation-manager' => $resource::getBreadcrumb()],
default => [$ancestorResource::getUrl('edit', $urlParameters) . '#relation-manager' => $resource::getBreadcrumb()],
};
} else {
$index = [$resource::getUrl('index') => $resource::getBreadcrumb()];
}
Expand Down

0 comments on commit e50393f

Please sign in to comment.