Skip to content

Guard edit button script against missing edit route in ModelListType - #8382

Merged
VincentLanglet merged 1 commit into
sonata-project:4.xfrom
EmmanuelVella:fix/model-list-edit-script-missing-route
Jun 3, 2026
Merged

Guard edit button script against missing edit route in ModelListType#8382
VincentLanglet merged 1 commit into
sonata-project:4.xfrom
EmmanuelVella:fix/model-list-edit-script-missing-route

Conversation

@EmmanuelVella

Copy link
Copy Markdown
Contributor

Subject

When a ModelListType (sonata_type_model_list) field points to an admin whose edit route has been
removed in configureRoutes(), rendering the edit form throws
RuntimeException: unable to find the route "<admin>.edit".

The visible edit button in Form/form_admin_fields.html.twig is correctly guarded by
hasroute('edit') and hasAccess('edit') and btn_edit, but the companion script in
CRUD/Association/edit_many_script.html.twig guarded the associationadmin.generateUrl('edit', ...)
call (and the related btn-warning toggle) with btn_edit only. As btn_edit defaults to the truthy
'link_edit', the URL generation runs even when the route does not exist, crashing the whole form
rendering.

This aligns the script's guards with the widget's, so the edit URL is only generated when the associated
admin actually has an accessible edit route.

I am targeting this branch, because it is a backwards-compatible bugfix.

Steps to reproduce

  1. Create an admin whose configureRoutes() calls $collection->remove('edit').
  2. Reference it from another admin via a ModelListType form field, and set a value on that field.
  3. Open the other admin's edit page → RuntimeException: unable to find the route "...edit".

Changelog

### Fixed
- Do not generate the edit button URL in `edit_many_script` when the associated admin has no accessible `edit` route

When a ModelListType field points to an admin whose edit route was removed in
configureRoutes(), the edit_many_script template still generated the edit URL
because it was guarded by btn_edit only, throwing "unable to find the route"
while rendering the form. Align the guards with the visible button in
form_admin_fields.html.twig (hasroute('edit') and hasAccess('edit') and btn_edit).
@EmmanuelVella
EmmanuelVella force-pushed the fix/model-list-edit-script-missing-route branch from 9dfd616 to fd3ae0e Compare June 1, 2026 13:24
@EmmanuelVella
EmmanuelVella marked this pull request as draft June 1, 2026 13:24
@EmmanuelVella
EmmanuelVella marked this pull request as ready for review June 1, 2026 13:26

@dmaicher dmaicher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dmaicher
dmaicher requested a review from VincentLanglet June 3, 2026 12:25
@dmaicher

dmaicher commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

PHPUnit test fails are unrelated and also happen on 4.x with Symfony 8.1

@VincentLanglet
VincentLanglet merged commit 7021c99 into sonata-project:4.x Jun 3, 2026
20 of 25 checks passed
@VincentLanglet

Copy link
Copy Markdown
Member

Thanks

@EmmanuelVella

Copy link
Copy Markdown
Contributor Author

Thank you !

@EmmanuelVella
EmmanuelVella deleted the fix/model-list-edit-script-missing-route branch June 3, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants