-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_node.module
28 lines (24 loc) · 916 Bytes
/
json_node.module
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
<?php
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
function json_node_form_system_site_information_settings_alter (array &$form, FormStateInterface $form_state, $form_id) {
$dvalue = 'No API Key yet';
$api = \Drupal::configFactory()->getEditable('system.site')->get('siteapikey');
if($api){
$dvalue = $api;
$form['actions']['submit']['#value'] = t('Update Configuration');
}
$form['site_api_key'] = [
'#type' => 'textfield',
'#title' => t('Site API Key'),
'#default_value' => $dvalue ,
'#weight' => -10
];
$form['#submit'][] = 'json_node_extra';
}
function json_node_extra ($form, FormStateInterface $form_state) {
\Drupal::configFactory()->getEditable('system.site')
->set('siteapikey', $form_state->getValue('site_api_key'))
->save();
drupal_set_message('Site API Key has been saved as -> '. $form_state->getValue('site_api_key'));
}