public function BlockerSettingsForm::buildForm in Cookie Content Blocker 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ BlockerSettingsForm.php, line 34
Class
- BlockerSettingsForm
- Form builder to manage settings related to the Cookie content blocker.
Namespace
Drupal\cookie_content_blocker\FormCode
public function buildForm(array $form, FormStateInterface $form_state) : array {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('cookie_content_blocker.settings');
$form['blocked_message'] = [
'#type' => 'textarea',
'#title' => $this
->t('Default message for blocked content'),
'#description' => $this
->t('When content is blocked and a message is shown, this message will be shown by default. Leave empty to use the default. Some basic HTML can be used.'),
'#default_value' => $config
->get('blocked_message') ?? $this
->t('You have not yet given permission to place the required cookies. Accept the required cookies to view this content.'),
];
$form['show_button'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show a button to change cookie consent below the message for blocked content'),
'#description' => $this
->t('When the button is shown the click event to change cookie consent will be turned on.'),
'#default_value' => $config
->get('show_button') ?? TRUE,
];
$form['button_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('The change cookie consent button text'),
'#default_value' => $config
->get('button_text') ?? $this
->t('Show content'),
'#states' => [
'visible' => [
':input[name="show_button"]' => [
'checked' => TRUE,
],
],
],
];
$form['enable_click_consent_change'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable changing consent by clicking on the blocked content'),
'#description' => $this
->t('To show the blocked content, consent to the placement of cookies has to be given. By enabling this setting clicking on the blocked content wrapper will let the user change consent.'),
'#default_value' => $config
->get('enable_click_consent_change') ?? TRUE,
'#states' => [
'visible' => [
':input[name="show_button"]' => [
'checked' => FALSE,
],
],
],
];
$form['consent_awareness'] = [
'#type' => 'details',
'#tree' => TRUE,
'#title' => $this
->t('Consent awareness'),
'#description' => $this
->t('Manage how Cookie content blocker knows about cookie consent and how it can change the consent. Note: only one cookie category is supported.'),
'#collapsible' => TRUE,
'#open' => TRUE,
'accepted' => [
'#type' => 'details',
'#title' => $this
->t('Consent given'),
'#description' => $this
->t('Define the event that is triggered when a visitor actively gives consent and the cookies to determine if consent already has been given earlier.'),
'#collapsible' => TRUE,
'#open' => FALSE,
],
'declined' => [
'#type' => 'details',
'#title' => $this
->t('Consent refused'),
'#description' => $this
->t('Define the event that is triggered when a visitor actively declines consent and the cookies to determine if consent already has been declined earlier.'),
'#collapsible' => TRUE,
'#open' => FALSE,
],
'change' => [
'#type' => 'details',
'#title' => $this
->t('Consent changed'),
'#description' => $this
->t('Define the event that has to be triggered when the button or blocked content placeholder is clicked.'),
'#collapsible' => TRUE,
'#open' => FALSE,
],
];
foreach (Element::children($form['consent_awareness']) as $event_type) {
$form['consent_awareness'][$event_type]['event'] = $this
->eventFormContainer($event_type);
if ($event_type === 'change') {
continue;
}
$form['consent_awareness'][$event_type]['cookie'] = $this
->cookieFormContainer($event_type);
}
return $form;
}