You are here

class GoogleAuthSettingsForm in Social Auth Google 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/GoogleAuthSettingsForm.php \Drupal\social_auth_google\Form\GoogleAuthSettingsForm
  2. 8 src/Form/GoogleAuthSettingsForm.php \Drupal\social_auth_google\Form\GoogleAuthSettingsForm

Settings form for Social Auth Google.

Hierarchy

Expanded class hierarchy of GoogleAuthSettingsForm

1 string reference to 'GoogleAuthSettingsForm'
social_auth_google.routing.yml in ./social_auth_google.routing.yml
social_auth_google.routing.yml

File

src/Form/GoogleAuthSettingsForm.php, line 12

Namespace

Drupal\social_auth_google\Form
View source
class GoogleAuthSettingsForm extends SocialAuthSettingsForm {

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

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return array_merge(parent::getEditableConfigNames(), [
      'social_auth_google.settings',
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('social_auth_google.settings');
    $form['google_settings'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Google Client settings'),
      '#open' => TRUE,
      '#description' => $this
        ->t('You need to first create a Google App at <a href="@google-dev">@google-dev</a>', [
        '@google-dev' => 'https://console.developers.google.com',
      ]),
    ];
    $form['google_settings']['client_id'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this
        ->t('Client ID'),
      '#default_value' => $config
        ->get('client_id'),
      '#description' => $this
        ->t('Copy the Client ID here.'),
    ];
    $form['google_settings']['client_secret'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this
        ->t('Client Secret'),
      '#default_value' => $config
        ->get('client_secret'),
      '#description' => $this
        ->t('Copy the Client Secret here.'),
    ];
    $form['google_settings']['authorized_redirect_url'] = [
      '#type' => 'textfield',
      '#disabled' => TRUE,
      '#title' => $this
        ->t('Authorized redirect URIs'),
      '#description' => $this
        ->t('Copy this value to <em>Authorized redirect URIs</em> field of your Google App settings.'),
      '#default_value' => Url::fromRoute('social_auth_google.callback')
        ->setAbsolute()
        ->toString(),
    ];
    $form['google_settings']['authorized_javascript_origin'] = [
      '#type' => 'textfield',
      '#disabled' => TRUE,
      '#title' => $this
        ->t('Authorized Javascript Origin'),
      '#description' => $this
        ->t('Copy this value to <em>Authorized Javascript Origins</em> field of your Google App settings.'),
      '#default_value' => $GLOBALS['base_url'],
    ];
    $form['google_settings']['advanced'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Advanced settings'),
      '#open' => FALSE,
    ];
    $form['google_settings']['advanced']['scopes'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Scopes for API call'),
      '#default_value' => $config
        ->get('scopes'),
      '#description' => $this
        ->t('Define any additional scopes to be requested, separated by a comma (e.g.: https://www.googleapis.com/auth/youtube.upload,https://www.googleapis.com/auth/youtube.readonly).<br>
                                  The scopes  \'openid\' \'email\' and \'profile\' are added by default and always requested.<br>
                                  You can see the full list of valid scopes and their description <a href="@scopes">here</a>.', [
        '@scopes' => 'https://developers.google.com/apis-explorer/#p/',
      ]),
    ];
    $form['google_settings']['advanced']['endpoints'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('API calls to be made to collect data'),
      '#default_value' => $config
        ->get('endpoints'),
      '#description' => $this
        ->t('Define the Endpoints to be requested when user authenticates with Google for the first time<br>
                                  Enter each endpoint in different lines in the format <em>endpoint</em>|<em>name_of_endpoint</em>.<br>
                                  <b>For instance:</b><br>
                                  /youtube/v3/playlists?maxResults=2&mine=true&part=snippet|playlists_list<br>'),
    ];
    $form['google_settings']['advanced']['restricted_domain'] = [
      '#type' => 'textfield',
      '#required' => FALSE,
      '#title' => $this
        ->t('Restricted Domain'),
      '#default_value' => $config
        ->get('restricted_domain'),
      '#description' => $this
        ->t('If you want to restrict the users to a specific domain, insert your domain here. For example mycollege.edu. Note that this works only for Google Apps hosted accounts.'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    $this
      ->config('social_auth_google.settings')
      ->set('client_id', trim($values['client_id']))
      ->set('client_secret', trim($values['client_secret']))
      ->set('scopes', $values['scopes'])
      ->set('endpoints', $values['endpoints'])
      ->set('restricted_domain', $values['restricted_domain'])
      ->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.
GoogleAuthSettingsForm::buildForm public function Form constructor. Overrides SocialAuthSettingsForm::buildForm
GoogleAuthSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides SocialAuthSettingsForm::getEditableConfigNames
GoogleAuthSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides SocialAuthSettingsForm::getFormId
GoogleAuthSettingsForm::submitForm public function Form submission handler. Overrides SocialAuthSettingsForm::submitForm
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.
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.
SocialAuthSettingsForm::$routeProvider protected property The route provider.
SocialAuthSettingsForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
SocialAuthSettingsForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
SocialAuthSettingsForm::__construct public function Constructor. Overrides ConfigFormBase::__construct
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.