Skip to content

Commit

Permalink
bug #6252 Admin Url Fix for linking from Edit/Detail to Index pages. …
Browse files Browse the repository at this point in the history
…(bytes-commerce)

This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Admin Url Fix for linking from Edit/Detail to Index pages.

Scenario:
* have two entity CRUD forms
* have some entities in Entity 1
* have a few, or none in Entity 2
* have a association or relation to Entity 2 from Entity 1, but allow it to be null and let it be null (no links existing)
* have a link to the Crud Index for Entity 2 in the Form of Entity 1 (when updating / FK existing)
* click the link

Expected result:
* you get redirected to the Index Page of the desired CRUD

Result:
* Exception, as the FK of Entity 1 does not exist in Entity 2
* and if it would, it would be the wrong one, but thats not a bug / exception

The main point is that the current setup assumes that there will always be existing links. Since non-referring pages like the Index do not need the entityId parameter, we can unset it when the scenario is matched (URL goes to Index, EntityId is set).

Commits
-------

54e8c80 Admin Url Fix for linking from Edit/Detail to Index pages.
  • Loading branch information
javiereguiluz committed Oct 17, 2024
2 parents cfb7348 + 54e8c80 commit 304ebb1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Router/AdminUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public function generateUrl(): string
$this->unset(EA::DASHBOARD_CONTROLLER_FQCN);
}

// if the current action is 'index' and an entity ID is defined, remove the entity ID to prevent exceptions automatically
if (Action::INDEX === $this->get(EA::CRUD_ACTION) && null !== $this->get(EA::ENTITY_ID)) {
$this->unset(EA::ENTITY_ID);
}

// this happens when generating URLs from outside EasyAdmin (AdminContext is null) and
// no Dashboard FQCN has been defined explicitly
if (null === $this->dashboardRoute) {
Expand Down

0 comments on commit 304ebb1

Please sign in to comment.