Skip to content

Commit

Permalink
UHF-10444: Fix user redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Nov 1, 2024
1 parent 0ca2292 commit 15e41da
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions public/modules/custom/infofinland_common/infofinland_common.module
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,32 @@ function infofinland_common_media_presave(Media $entity) {
}
}

/**
* Implements hook_form_FORM_ID_alter().
*/
function infofinland_common_form_user_login_form_alter(&$form, FormStateInterface $form_state): void {
array_unshift($form['#submit'], 'infofinland_common_user_login_submit');
}

/**
* Form submission handler for user_login_form().
*
* Redirects the user to the content page after logging in.
*/
function infofinland_common_user_login_submit(&$form, FormStateInterface $form_state): void {
$url = Url::fromRoute('view.content.page_1');

// Check if a destination was set, probably on an exception controller.
// @see \Drupal\user\Form\UserLoginForm::submitForm()
$request = \Drupal::service('request_stack')->getCurrentRequest();
if (!$request->request->has('destination')) {
$request->query->set('destination', $url->toString());
}
else {
$request->query->set('destination', $request->request->get('destination'));
}
}

/**
* Implements hook_ckeditor_css_alter().
*/
Expand Down

0 comments on commit 15e41da

Please sign in to comment.