class SettingsFormWarning in General Data Protection Regulation Compliance 8
Implements the form controller.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\gdpr_compliance\Form\SettingsFormWarning
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsFormWarning
1 string reference to 'SettingsFormWarning'
File
- src/
Form/ SettingsFormWarning.php, line 16
Namespace
Drupal\gdpr_compliance\FormView source
class SettingsFormWarning extends ConfigFormBase {
protected $moduleHandler;
protected $entityTypeManager;
protected $entityTypeBundle;
protected $entityTypes;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('entity_type.manager'), $container
->get('entity_type.bundle.info'));
}
/**
* SettingsFormWarning constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Config factory service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* Module handler service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity Manager service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfo $entityTypeManager
* Entity Manager service.
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $moduleHandler, EntityTypeManagerInterface $entityTypeManager, EntityTypeBundleInfo $entityTypeBundle) {
$this->moduleHandler = $moduleHandler;
$this->entityTypeManager = $entityTypeManager;
$this->entityTypeBundle = $entityTypeBundle;
$this->entityTypes = [
'contact_message' => [
'name' => 'Contact',
'module' => 'contact',
],
'node' => [
'name' => 'Node',
'module' => 'node',
],
'webform' => [
'name' => 'Webform',
'module' => 'webform',
],
];
parent::__construct($config_factory);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'gdpr_compliance';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'gdpr_compliance.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('gdpr_compliance.settings');
$form['from-morelink'] = [
'#title' => $this
->t('Url for form [Link to site policy agreement].'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $config
->get('from-morelink'),
'#description' => $this
->t('Relative path starts with "/", or absolute start with http/https.'),
];
$form['user'] = [
'#type' => 'details',
'#title' => $this
->t('@module GDPR form warning', [
'@module' => 'user',
]),
'#open' => TRUE,
];
$form["user"]['user-register'] = [
'#title' => $this
->t('Enable on user registration'),
'#description' => $this
->t('Display alert on user-register form (/user/register).'),
'#type' => 'checkbox',
'#default_value' => $config
->get('user-register'),
];
$form["user"]['user-login'] = [
'#title' => $this
->t('Enable on user login'),
'#description' => $this
->t('Display alert on user-login form (/user/login).'),
'#type' => 'checkbox',
'#default_value' => $config
->get('user-login'),
];
foreach ($this->entityTypes as $enity_type => $enity_info) {
$name = $enity_info['name'];
$form[$enity_type] = [
'#type' => 'details',
'#title' => $this
->t('@name GDPR form warning', [
'@name' => $name,
]),
'#open' => TRUE,
];
if (!$this->moduleHandler
->moduleExists($enity_info['module'])) {
$form[$enity_type]['#open'] = FALSE;
$form[$enity_type]["{$enity_type}-miss"] = [
'#markup' => '<p>' . $this
->t("Module '@module' not enabled.", [
'@module' => $name,
]) . '</p>',
];
}
else {
$form[$enity_type]["{$enity_type}-mode"] = [
'#title' => $this
->t("Display mode"),
'#type' => 'radios',
'#options' => [
'disable' => 'Disable',
'all' => 'All',
'custom' => 'Custom bundles',
],
'#default_value' => $config
->get("{$enity_type}-mode"),
];
$options = [];
$bundles = $this
->getBundles($enity_type);
if (!empty($bundles)) {
foreach ($bundles as $key => $value) {
$options[$key] = $value['label'];
}
$form[$enity_type]["{$enity_type}-bundles"] = [
'#title' => $this
->t("@name bundles warning display on", [
'@name' => $name,
]),
'#type' => 'checkboxes',
'#options' => $options,
];
$default = $config
->get("{$enity_type}-bundles");
if (!empty($default)) {
$form[$enity_type]["{$enity_type}-bundles"]['#default_value'] = $default;
}
}
}
}
return parent::buildForm($form, $form_state);
}
/**
* Implements a form submit handler.
*/
private function getBundles($enity_type) {
if ($enity_type == 'webform') {
$wforms = $this->entityTypeManager
->getStorage('webform')
->loadMultiple();
$bundles = [];
foreach ($wforms as $wform) {
$bundles[$wform
->id()]['label'] = $wform
->label();
}
}
else {
$bundles = $this->entityTypeBundle
->getBundleInfo($enity_type);
}
return $bundles;
}
/**
* Implements a form submit handler.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->setRebuild(TRUE);
$config = $this
->config('gdpr_compliance.settings');
foreach ($this->entityTypes as $enity_type => $enity_info) {
$config
->set("{$enity_type}-mode", $form_state
->getValue("{$enity_type}-mode"))
->set("{$enity_type}-bundles", $form_state
->getValue("{$enity_type}-bundles"));
}
$config
->set('from-morelink', $form_state
->getValue('from-morelink'))
->set('user-login', $form_state
->getValue('user-login'))
->set('user-register', $form_state
->getValue('user-register'))
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SettingsFormWarning:: |
protected | property | ||
SettingsFormWarning:: |
protected | property | ||
SettingsFormWarning:: |
protected | property | ||
SettingsFormWarning:: |
protected | property | ||
SettingsFormWarning:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsFormWarning:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SettingsFormWarning:: |
private | function | Implements a form submit handler. | |
SettingsFormWarning:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsFormWarning:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsFormWarning:: |
public | function |
Implements a form submit handler. Overrides ConfigFormBase:: |
|
SettingsFormWarning:: |
public | function |
SettingsFormWarning constructor. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |