Repository URL to install this package:
|
Version:
1.1.0 ▾
|
<?php
/**
* @file
* Contains Drupal\welcome\Form\MessagesForm.
*/
namespace Drupal\cookie_info\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Configure Cookie Info settings for this site.
*
* @package Drupal\cookie_info\Form
*/
class CookieInfoSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getEditableConfigNames() {
return [
'cookie_info.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'cookie_info_admin_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('cookie_info.settings');
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Title'),
'#default_value' => $config->get('title'),
];
$form['body'] = [
'#type' => 'text_format',
'#title' => $this->t('Body'),
'#format' => $config->get('body.format'),
'#default_value' => $config->get('body.value'),
'#allowed_formats' => [$config->get('body.format')],
];
$form['open'] = [
'#type' => 'textfield',
'#title' => $this->t('Open button text'),
'#default_value' => $config->get('open'),
];
$form['close'] = [
'#type' => 'textfield',
'#title' => $this->t('Close button text'),
'#default_value' => $config->get('close'),
];
$form['show_once'] = [
'#type' => 'checkbox',
'#title' => $this->t('Only show popup once'),
'#description' => $this->t('Will set an "cookie_info" cookie which will expire in 365 days.'),
'#default_value' => $config->get('show_once'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->config('cookie_info.settings')
->set('title', $form_state->getValue('title'))
->set('body', $form_state->getValue('body'))
->set('open', $form_state->getValue('open'))
->set('close', $form_state->getValue('close'))
->set('show_once', $form_state->getValue('show_once'))
->save();
}
}