Redirect user after login

PHOTO EMBED

Thu Jan 18 2024 15:28:25 GMT+0000 (Coordinated Universal Time)

Saved by @saida

// file modules/custom/mymodule/mymodule.module



/**
 * Implements hook_form_alter().
 */
function henka_training_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($form_id == 'user_login_form') {
     $form['#submit'][] = 'redirect_submit_handler';
  }
}

/**
* Custom submit handler for login form.
*/
function redirect_submit_handler($form, FormStateInterface $form_state) {
   $url = Url::fromUri('internal:/formacion'); 
  // or $url = Url::fromRoute('view.VIEW_MACHINE_NAME.PAGE_MACHINENAME');
  //example  $url = Url::fromRoute('view.henka_training.page_training');
   $form_state->setRedirectUrl($url);
}
content_copyCOPY