Explain "suppress_admin" use-case

Created on 22 October 2024, 25 days ago

Problem/Motivation

The settings form has the following option:

$form['suppress_admin'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Do not redirect on admin form'),
      '#description' => $this->t('Checking this box will cause the redirect destination to apply only to anonymous user registration.'),
      '#default_value' => $config->get('suppress_admin'),
    ];

and the implementation is:

$redirect_config = \Drupal::config('redirect_after_registration.settings');
  // Do not redirect if user is not anonymous, and admin setting is unchecked.
  $suppress_redirect = $redirect_config->get('suppress_admin') && !\Drupal::currentUser()
      ->isAnonymous();
  if (!$suppress_redirect && !empty($redirect_config->get('destination'))) {
    $url = Url::fromUri('internal:' . $redirect_config->get('destination'));
    $form_state->setRedirectUrl($url);
  }

But how can a logged in user ever submit the registration form?
Or does that happen, if a user is created in the user creation admin form at /admin/people/create?

In that case, we should IMHO not even register the submit callback in:

/**
 * Implements hook_form_FORM_alter().
 *
 * Adds method to submit handler to redirect after form submission.
 */
function redirect_after_registration_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_register_form':
      $form['actions']['submit']['#submit'][] = '_redirect_after_registration_user_register_submit';
      break;
  }
}

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024