You are here

public function SocialAuthSettingsForm::buildForm in Social Auth 8.2

Same name and namespace in other branches
  1. 8 src/Form/SocialAuthSettingsForm.php \Drupal\social_auth\Form\SocialAuthSettingsForm::buildForm()
  2. 3.x src/Form/SocialAuthSettingsForm.php \Drupal\social_auth\Form\SocialAuthSettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/SocialAuthSettingsForm.php, line 65

Class

SocialAuthSettingsForm
Defines a form that configures Social Auth settings.

Namespace

Drupal\social_auth\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $social_auth_config = $this
    ->config('social_auth.settings');
  $form['social_auth'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Social Auth Settings'),
    '#open' => TRUE,
    '#description' => $this
      ->t('These settings allow you to configure how Social Auth module behaves on your Drupal site'),
  ];
  $form['social_auth']['post_login'] = [
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => $this
      ->t('Post login path'),
    '#description' => $this
      ->t('Path where the user should be redirected after a successful login. It must begin with <em>/, #</em> or <em>?</em>.'),
    '#default_value' => $social_auth_config
      ->get('post_login'),
  ];
  $form['social_auth']['user_allowed'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('What can users do?'),
    '#default_value' => $social_auth_config
      ->get('user_allowed'),
    '#options' => [
      'register' => $this
        ->t('Register and login'),
      'login' => $this
        ->t('Login only'),
    ],
  ];
  $form['social_auth']['redirect_user_form'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Redirect new users to Drupal user form'),
    '#description' => $this
      ->t('If you check this, new users are redirected to Drupal user form after the user is created. This is useful if you want to encourage users to fill in additional user fields.'),
    '#default_value' => $social_auth_config
      ->get('redirect_user_form'),
  ];
  $form['social_auth']['disable_admin_login'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable Social Auth login for administrator'),
    '#description' => $this
      ->t('Disabling Social Auth login for administrator (<em>user 1</em>) can help protect your site if a security vulnerability is ever discovered in some Social Network PHP SDK or this module.'),
    '#default_value' => $social_auth_config
      ->get('disable_admin_login'),
  ];

  // Option to disable Social Auth for specific roles.
  $roles = user_roles();
  $options = [];
  foreach ($roles as $key => $role_object) {
    if ($key != 'anonymous' && $key != 'authenticated') {
      $options[$key] = Html::escape($role_object
        ->get('label'));
    }
  }
  $form['social_auth']['disabled_roles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Disable Social Auth login for the following roles'),
    '#options' => $options,
    '#default_value' => $social_auth_config
      ->get('disabled_roles'),
  ];
  if (empty($roles)) {
    $form['social_auth']['disabled_roles']['#description'] = $this
      ->t('No roles found.');
  }
  return parent::buildForm($form, $form_state);
}