Problem/Motivation
Currently when controller returns redirect response the destination still takes over, causing controller to update request object. That's because of code in \Drupal\Core\EventSubscriber\RedirectResponseSubscriber::checkRedirectUrl()
$destination = $request->query->get('destination');
if ($destination) {
// The 'Location' HTTP header must always be absolute.
$destination = $this->getDestinationAsAbsoluteUrl($destination, $request->getSchemeAndHttpHost());
try {
$response->setTargetUrl($destination);
Proposed resolution
Make a destination service to update request object or document current behaviour
Remaining tasks
decide on approach, review patch
User interface changes
API changes
Data model changes
Comments
Comment #2
andypostI think that bug, because redirect response is overriden by destination
Comment #3
andypostFaced in masquerade module http://cgit.drupalcode.org/masquerade/tree/src/Controller/SwitchControll...
Comment #5
dawehnerDo you remember the behaviour of D7? Wasn't that basically the same, see
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_goto/7Comment #6
andypostYep, they looks the same (except d7 checks for external URL) and CR https://www.drupal.org/node/2023537 suggests to override response with subscriber.
But this is a strange from DX POV - that you need to use subscriber to make sure-sure that redirect will happen
Also the patch point to "readability" of destination service, you can set destination but core will not use that data... always taking destination from request but not the service, that makes useless the set() method
Comment #7
andypost@dawehner there's existing bug in core that affects end-users
Steps to reproduce:
1) Visit
admin/contentand click "edit" any node2) on node edit page click "Preview"
3) expected preview but actually you will be redirected back to
admin/contentComment #8
Anonymous (not verified) commented@andypost I actually wrote a helper function to solve this issue in the related ticket (https://www.drupal.org/node/2325463), the functionality could be moved onto the destination service instead?
The behaviour should ideally be documented so that developers are aware that it is necessary to pass through the destination query.
Comment #24
smustgrave commentedThis appears to be a duplicate of #2950883: Allow form redirects to ignore ?destination query parameter