Last active
July 19, 2016 20:23
-
-
Save gvso/505503c00d3795f783dc64ee7852dbfd to your computer and use it in GitHub Desktop.
Social Auth Google - Settings Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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