NoscriptTagSettingsForm.php in Noscript Tag 8
File
src/Form/NoscriptTagSettingsForm.php
View source
<?php
namespace Drupal\noscript_tag\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\ConfigFormBase;
class NoscriptTagSettingsForm extends ConfigFormBase {
public function getEditableConfigNames() {
return [
'noscript_tag.settings',
];
}
public function getFormId() {
return 'noscript_tag_setting_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('noscript_tag.settings');
$form = [];
$form = [
'noscript_tag_value' => [
'#type' => 'text_format',
'#title' => $this
->t('Enter message to display in noscript tag:'),
'#description' => $this
->t('Please enter your message which you want to display users that have disabled scripts in their browser or have a browser that does not support script tag.'),
'#default_value' => $config
->get('noscript_tag_value') ? $config
->get('noscript_tag_value') : $this
->t('Your browser does not support javascript!'),
'#format' => $config
->get('noscript_tag_format') ? $config
->get('noscript_tag_format') : 'basic_html',
'#rows' => 5,
'#cols' => 10,
'#resizable' => TRUE,
],
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$submitted_message = $form_state
->getValue('noscript_tag_value');
$noscript_tag_value = $submitted_message['value'];
$noscript_tag_format = $submitted_message['format'];
$this
->config('noscript_tag.settings')
->set('noscript_tag_value', $noscript_tag_value)
->set('noscript_tag_format', $noscript_tag_format)
->save();
parent::submitForm($form, $form_state);
}
}