Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Social Auth Google - Settings Form
<?php
namespace Drupal\social_auth_google\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Settings form for Social Auth Google.
*/
class GoogleAuthSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return array('social_auth_google.settings');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'social_auth_google_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('social_auth_google.settings');
$form['google_settings'] = array(
'#type' => 'details',
'#title' => $this->t('Google Client settings'),
'#open' => TRUE,
);
$form['google_settings']['client_id'] = array(
'#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'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => $this->t('Client Secret'),
'#default_value' => $config->get('client_secret'),
'#description' => $this->t('Copy the Client Secret here'),
);
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', $values['client_id'])
->set('client_secret', $values['client_secret'])
->save();
parent::submitForm($form, $form_state);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment