[Routing] Fix addNamePrefix breaking aliases to external routes #62460
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using
name_prefixon an import,RouteCollection::addNamePrefix()unconditionally prefixes the target of all aliases.If an alias points to an external route (a route not present in the imported collection), the link breaks because the external route name is not actually changed.
This PR ensures we only prefix the alias target if that target exists within the collection being modified.
Inside
routes/admin.yaml, I have an alias pointing to a global route defined elsewhere (app_logout):Before:
php bin/console cache:clearfails because the dumper tries to find the prefixed target (admin_app_logout) which does not exist:After:
The alias correctly points to the original
app_logoutroute and the cache warms up successfully: