Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace Drupal\social_auth_digitalocean\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\Routing\RequestContext;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\social_auth\Form\SocialAuthSettingsForm;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Settings form for Social Auth Digitalocean.
*/
class DigitaloceanAuthSettingsForm extends SocialAuthSettingsForm {
/**
* The request context.
*
* @var \Drupal\Core\Routing\RequestContext
*/
protected $requestContext;
/**
* Constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* Used to check if route exists.
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* Used to check if path is valid and exists.
* @param \Drupal\Core\Routing\RequestContext $request_context
* Holds information about the current request.
*/
public function __construct(ConfigFactoryInterface $config_factory, RouteProviderInterface $route_provider, PathValidatorInterface $path_validator, RequestContext $request_context) {
parent::__construct($config_factory, $route_provider, $path_validator);
$this->requestContext = $request_context;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
// Instantiates this class.
return new static(
// Load the services required to construct this class.
$container->get('config.factory'),
$container->get('router.route_provider'),
$container->get('path.validator'),
$container->get('router.request_context')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'social_auth_digitalocean_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return array_merge(
parent::getEditableConfigNames(),
['social_auth_digitalocean.settings']
);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('social_auth_digitalocean.settings');
$form['digitalocean_settings'] = [
'#type' => 'details',
'#title' => $this->t('Digitalocean Client settings'),
'#open' => TRUE,
'#description' => $this->t('You need to first create a Digitalocean App at <a href="@digitalocean-dev">@digitalocean-dev</a>', ['@digitalocean-dev' => 'https://cloud.digitalocean.com/settings/api/applications']),
];
$form['digitalocean_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['digitalocean_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['digitalocean_settings']['authorized_redirect_url'] = [
'#type' => 'textfield',
'#disabled' => TRUE,
'#title' => $this->t('Application Callback URL'),
'#description' => $this->t('Copy this value to <em>Application Callback URL</em> field of your Digitalocean App settings.'),
'#default_value' => $GLOBALS['base_url'] . '/user/login/digitalocean/callback',
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$this->config('social_auth_digitalocean.settings')
->set('client_id', $values['client_id'])
->set('client_secret', $values['client_secret'])
->save();
parent::submitForm($form, $form_state);
}
}