Answers for "drupal 8 custom redirect after user registration"

0

drupal 8 custom redirect after user registration

/*
 * Allow redirect upon register
 */
function MYMODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  foreach (array_keys($form['actions']) as $action) {
    if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
      $form['actions'][$action]['#submit'][] = 'MYMODULE_redirect_new_registered_users';
    }
  }
}

/*
 * Redirection
 */
function MYMODULE_redirect_new_registered_users($form, FormStateInterface &$form_state) {
  $form_state->setRedirect('entity.node.canonical', ['node' => 'LANDING_PAGE_NID']);
}
Posted by: Guest on January-25-2022

Browse Popular Code Answers by Language