I have a custom form submit callback to redirect users to a specific page:
function MYMODULE_authfrontpageredirect_callback(array &$form, FormStateInterface &$form_state) {
$url = \Drupal::service('path.validator')->getUrlIfValid('node/16');
$form_state->setRedirect($url->getRouteName(), $url->getRouteParameters());
}
This works correctly unless the url has a destination
query string, such as
/node/add/mynode?destination=/user
In this case, the user will be redirected based on the query string (to /user
) instead of my submit handler destination (node/16
).
How do I forcibly override the destination
query string content for this submit handler?
This question is similar to this D7 question but since Drupal 8 has the Symfony routing system the answers there did not help me.