Skip to content

Commit ff3a7d7

Browse files
committed
bug #7465 Ease upgrade to EasyAdmin 5.x by supporting entity IDs in query params (javiereguiluz)
This PR was squashed before being merged into the 5.x branch. Discussion ---------- Ease upgrade to EasyAdmin 5.x by supporting entity IDs in query params As reported by a user on Symfony Slack, if a custom action of yours doesn't include the `entityId` as a route palceholder, the generated URL will include that as a query param. In 4.x that works but in 5.x it doesn't because it always expects the entit yID to be part of the route attributes. We partially support entity IDs in query params in 5.x branch, but this PR ensures we support it in the other missing places. Commits ------- b158d7d Ease upgrade to EasyAdmin 5.x by supporting entity IDs in query params
2 parents f387385 + b158d7d commit ff3a7d7

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

src/EventListener/ExceptionListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
final readonly class ExceptionListener
2323
{
2424
public function __construct(
25-
2625
private bool $kernelDebug,
2726
private AdminContextProviderInterface $adminContextProvider,
2827
private Environment $twig,

src/Factory/AdminContextFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private function getI18nDto(Request $request, DashboardDto $dashboardDto, ?CrudD
192192
if (null !== $crudDto) {
193193
$translationParameters['%entity_name%'] = basename(str_replace('\\', '/', $crudDto->getEntityFqcn()));
194194
$translationParameters['%entity_as_string%'] = null === $entityDto ? '' : (string) $entityDto;
195-
$translationParameters['%entity_id%'] = $entityId = $request->attributes->get(EA::ENTITY_ID);
195+
$translationParameters['%entity_id%'] = $entityId = $request->attributes->get(EA::ENTITY_ID) ?? $request->query->get(EA::ENTITY_ID);
196196
$translationParameters['%entity_short_id%'] = null === $entityId ? null : u($entityId)->truncate(7)->toString();
197197

198198
$entityInstance = null === $entityDto ? null : $entityDto->getInstance();
@@ -261,7 +261,7 @@ private function getEntityDto(Request $request, ?CrudDto $crudDto): ?EntityDto
261261
return null;
262262
}
263263

264-
$entityId = $request->attributes->get(EA::ENTITY_ID);
264+
$entityId = $request->attributes->get(EA::ENTITY_ID) ?? $request->query->get(EA::ENTITY_ID);
265265

266266
return $this->entityFactory->create($crudDto->getEntityFqcn(), $entityId, $crudDto->getEntityPermission());
267267
}

0 commit comments

Comments
 (0)