Newer
Older

Yasmeen Abuerrub
committed
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
<?php
/**
* @file
* FormBit file for varbase_auth feature mdoule.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Get editable config names.
*
* @return array
* Array of config names, and list of values.
*/
function varbase_auth_get_editable_config_names() {
$editable_cofnigs = [
'simple.settings' => [
'social_auth_type' => ['social_auth_google'],
],
];
return $editable_cofnigs;
}
/**
* Build form bit.
*
* @param array $formbit
* FormBit for the form.
* @param Drupal\Core\Form\FormStateInterface $form_state
* Form status.
* @param array $install_state
* Install state.
*/
function varbase_auth_build_formbit(array &$formbit, FormStateInterface &$form_state, array &$install_state = NULL) {
$formbit['social_auth_type'] = [
'#type' => 'checkboxes',
'#title' => t('Social authentications to enable'),
'#default_value' => ['social_auth_google'],
'#options' => [
'social_auth_google' => t('Google +'),
'social_auth_facebook' => t('Facebook'),
'social_auth_linkedin' => t('Linkedin'),
'social_auth_twitter' => t('Twitter'),
],
];
}
/**
* Submit form bit with editable config values.
*
* To update the editable config in drupal active config.
*
* @param array $editable_config_values
* Editable cofnig values.
*/
function varbase_auth_submit_formbit(array $editable_config_values) {
$configFactory = \Drupal::configFactory()->getEditable('simple.settings');
$configFactory->set('social_auth_type', $editable_config_values['simple.settings']['social_auth_type']);
$configFactory->save(TRUE);
_varbase_auth_enable_modules();
}
/**
* Custom function to get checked values.
*
* From the Config and enable the modules.
*/

Rajab Natshah
committed
function _varbase_auth_enable_modules() {

Yasmeen Abuerrub
committed
$configFactory = \Drupal::configFactory()->getEditable('simple.settings');

Rajab Natshah
committed
$auth_modules = $configFactory->get('social_auth_type');
if (isset($auth_modules) && is_array($auth_modules) && count($auth_modules) > 0) {
$modules_to_install = [];
foreach ($auth_modules as $auth_module_index => $auth_module) {
if (is_string($auth_module)) {
array_push($modules_to_install, $auth_module);

Yasmeen Abuerrub
committed
}
}

Rajab Natshah
committed
if (isset($modules_to_install) && is_array($modules_to_install) && count($modules_to_install) > 0) {
\Drupal::service('module_installer')->install($modules_to_install);
}