You are here

class OpenIdConnectSettingsForm in Simple OAuth (OAuth2) & OpenID Connect 5.x

The settings form.

@internal

Hierarchy

Expanded class hierarchy of OpenIdConnectSettingsForm

1 string reference to 'OpenIdConnectSettingsForm'
simple_oauth.routing.yml in ./simple_oauth.routing.yml
simple_oauth.routing.yml

File

src/Form/OpenIdConnectSettingsForm.php, line 16

Namespace

Drupal\simple_oauth\Form
View source
class OpenIdConnectSettingsForm extends ConfigFormBase {

  /**
   * The claim names.
   *
   * @var string[]
   */
  private $claimNames;

  /**
   * Oauth2TokenSettingsForm constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   * @param string[] $claim_names
   *   The names of the claims.
   */
  public function __construct(ConfigFactoryInterface $config_factory, array $claim_names) {
    parent::__construct($config_factory);
    $this->claimNames = $claim_names;
  }

  /**
   * Creates the form.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The container.
   *
   * @return \Drupal\simple_oauth\Form\OpenIdConnectSettingsForm
   *   The form.
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->getParameter('simple_oauth.openid.claims'));
  }

  /**
   * Returns a unique string identifying the form.
   *
   * @return string
   *   The unique string identifying the form.
   */
  public function getFormId() {
    return 'openid_connect_settings';
  }

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

  /**
   * Defines the settings form for Access Token entities.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return array
   *   Form definition array.
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['disable_openid_connect'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable OpenID Connect'),
      '#description' => $this
        ->t('Disable OpenID Connect if you have a conflicting custom or contributed implementation of OpenID Connect in your site.'),
      '#default_value' => $this
        ->config('simple_oauth.settings')
        ->get('disable_openid_connect'),
    ];
    $form['info'] = [
      '#type' => 'container',
      'customize' => [
        '#markup' => '<p>' . $this
          ->t('Check the <a href="@href" rel="noopener" target="_blank">Simple OAuth guide</a> for OpenID Connect to learn how to customize the user claims for OpenID Connect.', [
          '@href' => Url::fromUri('https://www.drupal.org/node/3172149')
            ->toString(),
        ]) . '</p>',
      ],
      'claims' => [
        '#type' => 'checkboxes',
        '#title' => $this
          ->t('Available claims'),
        '#description' => $this
          ->t('Claims are defined and managed in the service container. They are only listed here for reference. Please see the documentation above for more information.'),
        '#options' => array_combine($this->claimNames, $this->claimNames),
        '#default_value' => $this->claimNames,
        '#disabled' => TRUE,
      ],
      '#states' => [
        'invisible' => [
          ':input[name="disable_openid_connect"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $disable = $form_state
      ->getValue('disable_openid_connect');
    $config = $this
      ->config('simple_oauth.settings');
    $config
      ->set('disable_openid_connect', $disable);
    $config
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
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. 3
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.
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 72
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. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
OpenIdConnectSettingsForm::$claimNames private property The claim names.
OpenIdConnectSettingsForm::buildForm public function Defines the settings form for Access Token entities. Overrides ConfigFormBase::buildForm
OpenIdConnectSettingsForm::create public static function Creates the form. Overrides ConfigFormBase::create
OpenIdConnectSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
OpenIdConnectSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
OpenIdConnectSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
OpenIdConnectSettingsForm::__construct public function Oauth2TokenSettingsForm constructor. Overrides ConfigFormBase::__construct
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.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.