You are here

class SamlSpDrupalLoginConfig in SAML Service Provider 8.2

Same name and namespace in other branches
  1. 8.3 modules/saml_sp_drupal_login/src/Form/SamlSpDrupalLoginConfig.php \Drupal\saml_sp_drupal_login\Form\SamlSpDrupalLoginConfig
  2. 4.x modules/saml_sp_drupal_login/src/Form/SamlSpDrupalLoginConfig.php \Drupal\saml_sp_drupal_login\Form\SamlSpDrupalLoginConfig
  3. 3.x modules/saml_sp_drupal_login/src/Form/SamlSpDrupalLoginConfig.php \Drupal\saml_sp_drupal_login\Form\SamlSpDrupalLoginConfig

Hierarchy

Expanded class hierarchy of SamlSpDrupalLoginConfig

1 string reference to 'SamlSpDrupalLoginConfig'
saml_sp_drupal_login.routing.yml in modules/saml_sp_drupal_login/saml_sp_drupal_login.routing.yml
modules/saml_sp_drupal_login/saml_sp_drupal_login.routing.yml

File

modules/saml_sp_drupal_login/src/Form/SamlSpDrupalLoginConfig.php, line 17
Contains \Drupal\saml_sp_drupal_login\Form\SamlSpDrupalLoginConfig.

Namespace

Drupal\saml_sp_drupal_login\Form
View source
class SamlSpDrupalLoginConfig extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'saml_sp_drupal_login_config';
  }

  /**
   * Check if config variable is overridden by the settings.php.
   *
   * @param string $name
   *   SAML SP Drupal Login settings key.
   *
   * @return bool
   *   Boolean.
   */
  protected function isOverridden($name) {
    $original = $this->configFactory
      ->getEditable('saml_sp_drupal_login.config')
      ->get($name);
    $current = $this->configFactory
      ->get('saml_sp_drupal_login.config')
      ->get($name);
    return $original != $current;
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'saml_sp_drupal_login.config',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form = [], FormStateInterface $form_state) {
    $config = $this->configFactory
      ->get('saml_sp_drupal_login.config');
    $idps = array();

    // List all the IDPs in the system.
    foreach (saml_sp__load_all_idps() as $machine_name => $idp) {
      $idps[$idp->id] = $idp->label;
    }
    $form['config'] = [
      '#tree' => TRUE,
    ];
    $form['config']['idp'] = array(
      '#type' => 'checkboxes',
      '#options' => $idps,
      '#title' => $this
        ->t('IdP'),
      '#description' => $this
        ->t('Choose the IdP to use when authenticating Drupal logins'),
      '#default_value' => $config
        ->get('idp') ?: array(),
      '#disabled' => $this
        ->isOverridden('entity_id'),
      '#options' => $idps ?: array(),
    );
    $site_name = $this
      ->config('system.site')
      ->get('name');
    $form['config']['logout'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Single Log Out'),
      '#description' => $this
        ->t('When logging out of %site_name also log out of the IdP', array(
        '%site_name' => $site_name,
      )),
      '#default_value' => $config
        ->get('logout'),
      '#disabled' => $this
        ->isOverridden('logout'),
    );
    $form['config']['update_email'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Update Email address'),
      '#description' => $this
        ->t('If an account can be found on %site_name but the e-mail address differs from the one provided by the IdP update the email on record in Drupal with the new address from the IdP. This will only make a difference is the identifying information from the IdP is not the email address.', array(
        '%site_name' => $site_name,
      )),
      '#default_value' => $config
        ->get('update_email'),
      '#disabled' => $this
        ->isOverridden('update_email'),
    );
    $form['config']['update_language'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Update Language'),
      '#description' => $this
        ->t('If the account language of %site_name differs from that in the IdP response update to the user\'s account to match.', array(
        '%site_name' => $site_name,
      )),
      '#default_value' => $config
        ->get('update_language'),
      '#disabled' => $this
        ->isOverridden('update_language'),
    );
    $form['config']['no_account_authenticated_user_role'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Login users without a user account as an authenticated user.'),
      '#description' => $this
        ->t('If a user is authenticated by the SAML Service Provider but no matching account can be found the user will be logged in as an authenticated user. This will allow users to be authenticated to receive more permissions than an anonymous user but less than a user with any other role.'),
      '#default_value' => $config
        ->get('no_account_authenticated_user_role', FALSE),
      '#disabled' => $this
        ->isOverridden('no_account_authenticated_user_role'),
    );
    $uid = $config
      ->get('no_account_authenticated_user_account');
    $users = $uid ? User::loadMultiple(array(
      $uid => $uid,
    )) : array();
    if (isset($users[$uid])) {
      $user = $users[$uid];
    }
    else {
      $user = NULL;
    }
    if (!empty($users)) {
      $default_value = EntityAutocomplete::getEntityLabels($users);
    }
    else {
      $default_value = NULL;
    }
    $form['config']['no_account_authenticated_user_account'] = array(
      '#type' => 'entity_autocomplete',
      '#title' => $this
        ->t('Authenticated user account'),
      '#description' => $this
        ->t('This is the account with only the authenticated user role which a user is logged in as if no matching account exists. As this account will be used for all users make sure that this account has only the "Authenticated User" role.'),
      '#default_value' => $user,
      '#disabled' => $this
        ->isOverridden('no_account_authenticated_user_account'),
      '#target_type' => 'user',
      '#states' => array(
        'visible' => array(
          ':input[name="config[no_account_authenticated_user_role]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['config']['force_saml_only'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Force SAML Login'),
      '#description' => $this
        ->t('The User Login form will not be used, when an anonymous user goes to /user they will be automatically redirected to the SAML authentication page.'),
      '#default_value' => $config
        ->get('force_saml_only'),
      '#disabled' => $this
        ->isOverridden('force_saml_only'),
    );

    /*
        $form['config']['account_request'] = array(
          '#type'           => 'fieldset',
          '#title'          => $this->t('Accounts'),
          '#description'    => $this->t('Allow Users to request account creation.'),
          '#access'         => ($this->config('user.settings')->get('register') == USER_REGISTER_ADMINISTRATORS_ONLY ? 1 : 0),
        );
    /**/
    $form['config']['account_request_request_account'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Allow users without an account to request an account?'),
      '#description' => $this
        ->t('Since you only allow Administrators to create an account: <a href="@account_settings_url" target="_blank">see Account Settings page</a> should the user who authenticates against the SAML IdP be able to request an account from administrators?', array(
        '@account_settings_url' => \Drupal::url('entity.user.admin_form', array(), array(
          'absolute' => TRUE,
        )),
      )),
      '#default_value' => $config
        ->get('account_request_request_account'),
      '#disabled' => $this
        ->isOverridden('account_request_request_account'),
    );
    $site_mail = $this
      ->config('system.site')
      ->get('mail');
    $form['config']['account_request_site_mail'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Send request to site mail account ( @site_mail )', array(
        '@site_mail' => $site_mail,
      )),
      '#default_value' => $config
        ->get('account_request_site_mail'),
      '#disabled' => $this
        ->isOverridden('account_request_site_mail'),
      '#states' => array(
        'visible' => array(
          ':input[name="config[account_request_request_account]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $query = db_select('user__roles', 'ur');
    $query
      ->fields('ur', array(
      'entity_id',
    ));
    $query
      ->condition('ur.deleted', 0);
    $result = $query
      ->execute();
    $admin_options = array();
    $admins = User::loadMultiple($result
      ->fetchCol());
    foreach ($admins as $u) {
      $admin_options[$u
        ->id()] = $u
        ->getDisplayName() . ' - ' . $u
        ->getEmail();
    }
    $uid = $config
      ->get('account_request_site_administrators');
    $form['config']['account_request_site_administrators'] = array(
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Send request to Site Administrators'),
      '#description' => $this
        ->t('The request email will be sent to these site Administrators'),
      '#options' => $admin_options,
      '#default_value' => $config
        ->get('account_request_site_administrators') ?: array(),
      '#disabled' => $this
        ->isOverridden('account_request_site_administrators'),
      '#states' => array(
        'visible' => array(
          ':input[name="config[account_request_request_account]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('saml_sp_drupal_login.config');
    $values = $form_state
      ->getValues();
    foreach ($values['config'] as $key => $value) {
      $config
        ->set($key, $value);
    }
    $config
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
SamlSpDrupalLoginConfig::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
SamlSpDrupalLoginConfig::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
SamlSpDrupalLoginConfig::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
SamlSpDrupalLoginConfig::isOverridden protected function Check if config variable is overridden by the settings.php.
SamlSpDrupalLoginConfig::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.