You are here

function social_user_form_user_register_form_alter in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  2. 8 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  3. 8.2 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  4. 8.3 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  5. 8.5 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  6. 8.6 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  7. 8.7 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  8. 8.8 modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  9. 10.3.x modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  10. 10.0.x modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  11. 10.1.x modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()
  12. 10.2.x modules/social_features/social_user/social_user.module \social_user_form_user_register_form_alter()

Implements hook_form_FORM_ID_alter().

See also

\Drupal\user\RegisterForm

File

modules/social_features/social_user/social_user.module, line 55
The social user module alterations.

Code

function social_user_form_user_register_form_alter(&$form, FormStateInterface $form_state) {

  // By default notify the user of the new account.
  if (isset($form['account']['notify']) && $form['account']['notify']['#access'] === TRUE) {
    $form['account']['notify']['#default_value'] = 1;
  }

  // Treat the account container as a separate fieldset so it is properly themed
  // by the socialbase theme.
  if (isset($form['account'])) {
    $form['account']['#type'] = 'fieldset';
    $form['account']['#title'] = new TranslatableMarkup('Sign up with <b>email</b>');

    // If we have a help text then we display it to the user.
    $signup_help = \Drupal::config('social_user.settings')
      ->get('signup_help');
    if (!empty($signup_help)) {
      $form['account']['#description'] = $signup_help;
    }

    // Ensure fields have weights so other forms can add items.
    if (isset($form['account']['mail'])) {
      $form['account']['mail']['#weight'] = -150;
    }
    if (isset($form['account']['name'])) {
      $form['account']['name']['#weight'] = -100;
    }
    if (isset($form['account']['pass'])) {
      $form['account']['pass']['#weight'] = -50;
    }
    $link_options = [];

    // Preserve the destination parameter when a user logs in instead.
    $request = \Drupal::request();
    if ($request->query
      ->has('destination')) {
      $link_options['query'] = [
        'destination' => $request->query
          ->get('destination'),
      ];
    }
    $login_link = Link::createFromRoute(new TranslatableMarkup('Log in'), 'user.login', [], $link_options)
      ->toString();
    $form['account']['login-link'] = [
      '#markup' => new TranslatableMarkup("Have an account already? @link", [
        "@link" => $login_link,
      ]),
      '#weight' => 1000,
      '#cache' => [
        'contexts' => [
          'url.query_args',
        ],
      ],
    ];
  }

  // Add an extra validation option, to check for existing data.
  $form['#validate'][] = 'social_user_register_validate';
}