Problem/Motivation

When destination query parameter is present redirects point to that page instead of the path:

<page_url>/ce-api/node/add/foo?destination=bar should generate a frontend direct to /node/add/foo?destination=bar not /bar.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

useernamee created an issue. See original summary.

useernamee’s picture

It looks like this is not realy a lupus_ce_renderer but a designed behavior in \Drupal\Core\EventSubscriber\RedirectResponseSubscriber::checkRedirectUrl the destination parameter has precedence and is set as targetUrl on RedirectResponse.

      // Let the 'destination' query parameter override the redirect target.
      // If $response is already a SecuredRedirectResponse, it might reject the
      // new target as invalid, in which case proceed with the old target.
      $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);
        }
        catch (\InvalidArgumentException $e) {
        }
      }
fago’s picture

This is a Drupal feature - In general it makes sense, but not when we are doing admin fallback redirects (See https://www.drupal.org/project/lupus_ce_renderer/issues/3272161)

Could we undo/prevent this Drupal logic somehow - only for Drupal admin fallback redirects, but keep the original path as is, with destination parameter?

useernamee’s picture

Status: Active » Needs review

I've simply removed destination query parameter from request. I think this won't have any undesirable consequences (in cases where destination query parameter is actually desired). If later will be the case we can make it a bit more complicated and just add a lupus_ce_renderer_redirect attribute to request and then write a service decorator for RedirectResponseSubscriber that has another condition before applying the destination query parameter override.

For now this solution works:

<base-url>/ce-api/node/add/article?destination=bar => "<base-url>/node/add/article?destination=bar"

useernamee’s picture

fago’s picture

Status: Needs review » Reviewed & tested by the community

Yep, agreed. Patch looks good. Let's get it tested!

  • useernamee committed f0f5fa2a on 2.x
    Issue #3353656 by useernamee, fago: Destination query parameter should...
useernamee’s picture

Status: Reviewed & tested by the community » Fixed

Works on our ci environments and no regressions were recorded, Thus merging.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.