public function EuCookieComplianceConfigForm::buildForm in EU Cookie Compliance (GDPR Compliance) 8
Same name and namespace in other branches
- 2.0.x src/Form/EuCookieComplianceConfigForm.php \Drupal\eu_cookie_compliance\Form\EuCookieComplianceConfigForm::buildForm()
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/ EuCookieComplianceConfigForm.php, line 119
Class
- EuCookieComplianceConfigForm
- Provides settings for eu_cookie_compliance module.
Namespace
Drupal\eu_cookie_compliance\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('eu_cookie_compliance.settings');
$default_filter_format = filter_default_format();
$full_html_format = FilterFormat::load('full_html');
if (($default_filter_format === 'restricted_html' || $default_filter_format === 'plain_text') && !empty($full_html_format) && $full_html_format
->get('status')) {
$default_filter_format = 'full_html';
}
$consent_storages = \Drupal::service('plugin.manager.eu_cookie_compliance.consent_storage');
$plugin_definitions = $consent_storages
->getDefinitions();
$consent_storage_options = [];
$consent_storage_options['do_not_store'] = $this
->t('Do not store');
foreach ($plugin_definitions as $plugin_name => $plugin_definition) {
/** @var \Drupal\Core\StringTranslation\TranslatableMarkup $plugin_definition_name */
$plugin_definition_name = $plugin_definition['name'];
$consent_storage_options[$plugin_name] = $plugin_definition_name
->render();
}
$token_support = \Drupal::service('module_handler')
->moduleExists('token');
$form['popup_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable banner'),
'#default_value' => $config
->get('popup_enabled'),
];
// List of checkbox values.
$role_names = [];
// Permissions per role.
$role_permissions = [];
// Which checkboxes should be ticked.
$role_values = [];
$perm = 'display eu cookie compliance popup';
foreach ($this
->getRoles() as $role_name => $role) {
// Exclude Admin roles.
/** @var \Drupal\user\Entity\Role $role */
if (!$role
->isAdmin()) {
$role_names[$role_name] = $role
->label();
// Fetch permissions for the roles.
$role_permissions[$role_name] = $role
->getPermissions();
// Indicate whether the checkbox should be ticked.
if (in_array($perm, $role_permissions[$role_name])) {
$role_values[] = $role_name;
}
}
}
$form['permissions'] = [
'#type' => 'details',
'#title' => $this
->t('Permissions'),
'#open' => TRUE,
];
$form['permissions']['see_the_banner'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Display the banner for'),
'#options' => $role_names,
'#default_value' => $role_values,
];
$form['consent_option'] = [
'#type' => 'details',
'#title' => $this
->t('Consent for processing of personal information'),
'#open' => TRUE,
];
$form['consent_option']['info'] = [
'#type' => 'markup',
'#markup' => $this
->t("The EU General Data Protection Regulation (GDPR) (see <a href=\"https://www.eugdpr.org/\" target=\"_blank\">https://www.eugdpr.org/</a>) comes into enforcement from 25 May 2018 and introduces new requirements for web sites which handle information that can be used to identify individuals. The regulation underlines that consent must be <strong>unambiguous</strong> and involve a <strong>clear affirmative action</strong>. When evaluating how to best handle the requirements in the GDPR, remember that if you have a basic web site where the visitors don't log in, you always have the option to <strong>not process data that identifies individuals</strong>, in which case you may not need this module. Also note that GDPR applies to any electronic processing or storage of personal data that your organization may do, and simply installing a module may not be enough to become fully GDPR compliant."),
];
$form['consent_option']['method'] = [
'#type' => 'radios',
'#title' => $this
->t('Consent method'),
'#options' => [
'default' => $this
->t("Consent by default. Don't provide any option to opt out."),
'opt_in' => $this
->t("Opt-in. Don't track visitors unless they specifically give consent. (GDPR compliant)"),
'categories' => $this
->t('Opt-in with categories. Let visitors choose which cookie categories they want to opt-in for (GDPR compliant).'),
'opt_out' => $this
->t('Opt-out. Track visitors by default, unless they choose to opt out.'),
'auto' => $this
->t('Automatic. Respect the DNT (Do not track) setting in the browser, if present. Uses opt-in when DNT is 1 or not set, and consent by default when DNT is 0.'),
],
'#default_value' => $config
->get('method'),
];
$form['consent_per_category'] = [
'#type' => 'details',
'#title' => $this
->t('Cookie categories'),
'#open' => TRUE,
'#states' => [
'visible' => [
"input[name='method']" => [
'value' => 'categories',
],
],
],
];
$form['consent_per_category']['info'] = [
'#type' => 'markup',
'#markup' => $this
->t("Cookie categories are managed in the Categories tab (found at the top of this page)."),
];
$form['consent_per_category']['enable_save_preferences_button'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Replace the Agree button with "Save preferences" and "Accept all categories" buttons.'),
'#default_value' => $config
->get('enable_save_preferences_button'),
];
$form['consent_per_category']['save_preferences_button_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('"Save preferences" button label'),
'#default_value' => $config
->get('save_preferences_button_label'),
'#states' => [
'visible' => [
"input[name='enable_save_preferences_button']" => [
'checked' => TRUE,
],
],
'required' => [
"input[name='enable_save_preferences_button']" => [
'checked' => TRUE,
],
],
],
];
$form['consent_per_category']['accept_all_categories_button_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('"Accept all categories" button label'),
'#default_value' => $config
->get('accept_all_categories_button_label'),
'#states' => [
'visible' => [
"input[name='enable_save_preferences_button']" => [
'checked' => TRUE,
],
],
'required' => [
"input[name='enable_save_preferences_button']" => [
'checked' => TRUE,
],
],
],
];
$form['popup_info_template'] = [
'#type' => 'details',
'#title' => $this
->t("Select the popup info template for 'default by consent' option"),
'#open' => TRUE,
'#states' => [
'visible' => [
"input[name='method']" => [
'value' => 'default',
],
],
],
];
$form['popup_info_template']['popup_info_template'] = [
'#type' => 'radios',
'#title' => $this
->t('Info banner template'),
'#options' => [
'legacy' => $this
->t('Cookie policy button in popup-buttons section and styled similarly to the Agree button,
as in earlier versions of this module'),
'new' => $this
->t('Cookie policy button in popup-text section, styled differently than Agree button.'),
],
'#default_value' => $config
->get('popup_info_template'),
];
$form['javascripts'] = [
'#type' => 'details',
'#title' => $this
->t("Disable the following JavaScripts when consent isn't given"),
'#open' => TRUE,
'#states' => [
'visible' => [
"input[name='method']" => [
'!value' => 'default',
],
],
],
];
$form['javascripts']['disabled_javascripts'] = [
'#type' => 'textarea',
'#title' => $this
->t('Disable JavaScripts'),
'#default_value' => $config
->get('disabled_javascripts'),
'#description' => $this
->t("<span class='eu-cookie-compliance-word-break'>Include the full path of JavaScripts, each on a separate line. When using the opt-in or opt-out consent options, you can block certain JavaScript files from being loaded when consent isn't given. The on-site JavaScripts should be written as root relative paths <strong>without the leading slash</strong>, you can use public://path/to/file.js and private://path/to/file.js, and off-site JavaScripts should be written as complete URLs <strong>with the leading http(s)://</strong>. Note that after the user gives consent, the scripts will be executed in the order you enter here.<br /><br />Libraries and scripts that attach to Drupal.behaviors are supported. To indicate a behavior that needs to be loaded on consent, append the behavior name after the script with a | (vertical bar). If you also want to conditionally load a library, place that as the third parameter, following another | (vertical bar). <strong>Example: modules/custom/custom_module/js/custom.js|customModule|custom_module/custom_module</strong>.<br />If your script file does not attach to Drupal.attributes, you may skip the second parameter. <strong>Example: modules/custom/custom_module/js/custom.js||custom_module/custom_module</strong><br /><strong>Note that Drupal behavior name and library parameters are both optional</strong>, but may be required to achieve your objective.</span>") . '<br /><br />' . $this
->t('When using the consent method "Opt-in with categories", you can link the script to a specific category by using the format: "category:path/to/the/script.js".'),
];
$form['cookies'] = [
'#type' => 'details',
'#title' => $this
->t('Cookie handling'),
'#open' => TRUE,
'#states' => [
'visible' => [
"input[name='method']" => [
'!value' => 'default',
],
],
],
];
$form['cookies']['automatic_cookies_removal'] = [
'#type' => 'checkbox',
'#title' => $this
->t("Enable cookie(s) automatic-removal when consent isn't given."),
'#default_value' => !empty($config
->get('automatic_cookies_removal')) ? $config
->get('automatic_cookies_removal') : FALSE,
];
$form['cookies']['allowed_cookies'] = [
'#type' => 'textarea',
'#title' => $this
->t('Allowed cookies'),
'#default_value' => $config
->get('allowed_cookies'),
'#description' => $this
->t("Include the name of cookies, each on a separate line. When using the opt-in or opt-out consent options, this module will <strong>delete cookies from your domain that are not allowed</strong> every few seconds when consent isn't given. PHP session cookies and the cookie for this module are always allowed.") . '<br /><br />' . $this
->t('When using the consent method "Opt-in with categories", you can link the cookie to a specific consent category by using the format: "category:cookie_name". Only when consent is given for the given category, will the cookie be allowed.') . '<br />' . $this
->t('Cookie names can contain "*" characters which mean a series of any characters.'),
'#states' => [
'visible' => [
'input[name="automatic_cookies_removal"]' => [
'checked' => TRUE,
],
],
],
];
$form['consent_storage'] = [
'#type' => 'details',
'#title' => $this
->t('Store record of consent'),
'#open' => TRUE,
'#states' => [
'visible' => [
"input[name='method']" => [
'!value' => 'default',
],
],
],
];
$form['consent_storage']['info'] = [
'#type' => 'markup',
'#markup' => $this
->t('Depending on your implementation of GDPR, you may have to store a record when the user consents. This module comes with a basic consent storage plugin that writes a record to the database. Note that if your site has significant traffic, the basic consent storage may become a bottleneck, as every consent action will require a write to the database. You can easily create your own module with a ConsentStorage Plugin that extends ConsentStorageBase, using BasicConsentStorage from this module as a template. If you create a highly performant consent storage plugin, please consider contributing it back to the Drupal community as a contrib module.'),
];
$form['consent_storage']['consent_storage_method'] = [
'#type' => 'radios',
'#title' => $this
->t('Consent storage method'),
'#default_value' => $config
->get('consent_storage_method'),
'#options' => $consent_storage_options,
];
$form['popup_message'] = [
'#type' => 'details',
'#title' => $this
->t('Cookie information banner'),
'#open' => TRUE,
];
$form['popup_message']['popup_clicking_confirmation'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Consent by clicking'),
'#default_value' => $config
->get('popup_clicking_confirmation'),
'#description' => $this
->t('By default by clicking any link or button on the website the visitor accepts the cookie policy. Uncheck this box if you don’t require this functionality. You may want to edit the banner message below accordingly.'),
'#states' => [
'visible' => [
'input[name="method"]' => [
'value' => 'default',
],
],
],
];
$config_format = $config
->get('popup_info.format');
if (!empty($config_format)) {
$filter_format = FilterFormat::load($config_format);
if (empty($filter_format) || !$filter_format
->get('status')) {
$config_format = $default_filter_format;
}
}
$form['popup_message']['popup_info'] = [
'#type' => 'text_format',
'#title' => $this
->t('Cookie information banner message'),
'#default_value' => $config
->get('popup_info.value'),
'#required' => TRUE,
'#format' => $config_format,
];
if ($token_support) {
$form['popup_message']['tokens'] = [
'#theme' => 'token_tree_link',
'#token_types' => [],
];
}
$form['popup_message']['use_mobile_message'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use a different message for mobile phones.'),
'#default_value' => !empty($config
->get('use_mobile_message')) ? $config
->get('use_mobile_message') : FALSE,
];
$form['popup_message']['container'] = [
'#type' => 'container',
'#states' => [
'visible' => [
'input[name="use_mobile_message"]' => [
'checked' => TRUE,
],
],
],
];
$config_format = $config
->get('mobile_popup_info.format');
if (!empty($config_format)) {
$filter_format = FilterFormat::load($config_format);
if (empty($filter_format) || !$filter_format
->get('status')) {
$config_format = $default_filter_format;
}
}
$form['popup_message']['container']['mobile_popup_info'] = [
'#type' => 'text_format',
'#title' => $this
->t('Cookie information banner message - mobile'),
'#default_value' => $config
->get('mobile_popup_info.value'),
'#required' => FALSE,
'#format' => $config_format,
];
if ($token_support) {
$form['popup_message']['container']['tokens'] = [
'#theme' => 'token_tree_link',
'#token_types' => [],
];
}
$form['popup_message']['mobile_breakpoint'] = [
'#type' => 'number',
'#title' => $this
->t('Mobile breakpoint'),
'#default_value' => !empty($config
->get('mobile_breakpoint')) ? $config
->get('mobile_breakpoint') : '768',
'#field_suffix' => $this
->t('px'),
'#size' => 4,
'#maxlength' => 4,
'#required' => FALSE,
'#description' => $this
->t('The mobile message will be used when the window width is below or equal to the given value.'),
'#states' => [
'visible' => [
"input[name='use_mobile_message']" => [
'checked' => TRUE,
],
],
],
];
$form['popup_message']['popup_agree_button_message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Agree button label'),
'#default_value' => $config
->get('popup_agree_button_message'),
'#size' => 30,
'#states' => [
'visible' => [
[
"input[name='enable_save_preferences_button']" => [
'checked' => FALSE,
],
"input[name='method']" => [
'value' => 'categories',
],
],
[
"input[name='method']" => [
'!value' => 'categories',
],
],
],
'required' => [
[
"input[name='enable_save_preferences_button']" => [
'checked' => FALSE,
],
"input[name='method']" => [
'value' => 'categories',
],
],
[
"input[name='method']" => [
'!value' => 'categories',
],
],
],
],
];
$form['popup_message']['show_more_info'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show "Cookie Policy" and "More info" buttons'),
'#description' => $this
->t('If this option is checked, the cookie policy button will be shown on the site. Disabling this option will hide both the "Cookie Policy" button on the information banner and the "More info" button on the "Thank you" banner.'),
'#default_value' => $config
->get('show_more_info'),
];
$form['popup_message']['popup_more_info_button_message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cookie policy button label'),
'#default_value' => $config
->get('popup_more_info_button_message'),
'#size' => 30,
'#states' => [
'visible' => [
[
'input[name="show_more_info"]' => [
'checked' => TRUE,
],
],
],
'required' => [
[
'input[name="show_more_info"]' => [
'checked' => TRUE,
],
],
],
],
];
$form['popup_message']['disagree_button_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Disagree button label'),
'#default_value' => $config
->get('disagree_button_label'),
'#size' => 30,
'#states' => [
'visible' => [
'input[name="method"]' => [
'!value' => 'default',
],
],
'required' => [
'input[name="method"]' => [
'!value' => 'default',
],
],
],
];
$form['withdraw_consent'] = [
'#type' => 'details',
'#title' => $this
->t('Withdraw consent'),
'#open' => TRUE,
'#states' => [
'visible' => [
"input[name='method']" => [
'!value' => 'default',
],
],
],
];
$form['withdraw_consent']['info'] = [
'#type' => 'markup',
'#markup' => $this
->t('GDPR requires that withdrawing consent for handling personal information should be as easy as giving consent. This module offers a tab button that when clicked brings up a message and a button that can be used to withdraw consent.'),
];
$form['withdraw_consent']['withdraw_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable floating privacy settings tab and withdraw consent banner'),
'#default_value' => $config
->get('withdraw_enabled'),
];
$form['withdraw_consent']['settings_tab_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable floating privacy settings tab after withdrawing consent'),
'#default_value' => $config
->get('settings_tab_enabled'),
];
$form['withdraw_consent']['withdraw_button_on_info_popup'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Put the "Withdraw consent" button on the cookie information banner.'),
'#default_value' => $config
->get('withdraw_button_on_info_popup'),
'#states' => [
'visible' => [
"input[name='method']" => [
'value' => 'categories',
],
],
],
];
$config_format = $config
->get('popup_info.format');
if (!empty($config_format)) {
$filter_format = FilterFormat::load($config_format);
if (empty($filter_format) || !$filter_format
->get('status')) {
$config_format = $default_filter_format;
}
}
$form['withdraw_consent']['withdraw_message'] = [
'#type' => 'text_format',
'#title' => $this
->t('Withdraw consent banner message'),
'#default_value' => isset($config
->get('withdraw_message')['value']) ? $config
->get('withdraw_message')['value'] : '',
'#description' => $this
->t('Text that will be displayed in the banner that appears when the privacy settings tab is clicked.'),
'#format' => $config_format,
'#states' => [
'visible' => [
"input[name='withdraw_button_on_info_popup']" => [
'checked' => FALSE,
],
],
],
];
if ($token_support) {
$form['withdraw_consent']['tokens'] = [
'#theme' => 'token_tree_link',
'#token_types' => [],
];
}
$form['withdraw_consent']['withdraw_tab_button_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Privacy settings tab label'),
'#default_value' => $config
->get('withdraw_tab_button_label'),
'#description' => $this
->t('Tab button that reveals/hides the withdraw message and action button when clicked.'),
];
$form['withdraw_consent']['withdraw_action_button_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Withdraw consent button label'),
'#default_value' => $config
->get('withdraw_action_button_label'),
'#description' => $this
->t('This button will withdraw consent when clicked.'),
];
$form['thank_you'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Thank you banner'),
];
$form['thank_you']['popup_agreed_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable "Thank you" banner'),
'#default_value' => $config
->get('popup_agreed_enabled'),
];
$form['thank_you']['popup_hide_agreed'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Clicking hides "Thank you" banner.'),
'#default_value' => $config
->get('popup_hide_agreed'),
'#description' => $this
->t('Clicking a link or button hides the "Thank you" message automatically.'),
];
$config_format = $config
->get('popup_info.format');
if (!empty($config_format)) {
$filter_format = FilterFormat::load($config_format);
if (empty($filter_format) || !$filter_format
->get('status')) {
$config_format = $default_filter_format;
}
}
$form['thank_you']['popup_agreed'] = [
'#type' => 'text_format',
'#title' => $this
->t('"Thank you" banner message'),
'#default_value' => !empty($config
->get('popup_agreed')['value']) ? $config
->get('popup_agreed')['value'] : '',
'#format' => $config_format,
];
if ($token_support) {
$form['thank_you']['tokens'] = [
'#theme' => 'token_tree_link',
'#token_types' => [],
];
}
$form['thank_you']['popup_find_more_button_message'] = [
'#type' => 'textfield',
'#title' => $this
->t('More info button label'),
'#default_value' => $config
->get('popup_find_more_button_message'),
'#size' => 30,
'#states' => [
'visible' => [
[
'input[name="show_more_info"]' => [
'checked' => TRUE,
],
],
[
'input[name="method"]' => [
'!value' => 'default',
],
],
],
'required' => [
[
'input[name="show_more_info"]' => [
'checked' => TRUE,
],
],
[
'input[name="method"]' => [
'!value' => 'default',
],
],
],
],
];
$form['thank_you']['popup_hide_button_message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Hide button label'),
'#default_value' => $config
->get('popup_hide_button_message'),
'#size' => 30,
];
$form['privacy'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Privacy policy'),
];
$form['privacy']['popup_link'] = [
'#type' => 'textfield',
'#title' => $this
->t('Privacy policy link'),
'#default_value' => $config
->get('popup_link'),
'#maxlength' => 1024,
'#required' => TRUE,
'#description' => $this
->t('Enter link to your privacy policy or other page that will explain cookies to your users, external links should start with http:// or https://.'),
'#element_validate' => [
[
$this,
'validatePopupLink',
],
],
];
$form['privacy']['popup_link_new_window'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Open privacy policy link in a new window.'),
'#default_value' => $config
->get('popup_link_new_window'),
];
$form['version_set'] = [
'#type' => 'details',
'#title' => $this
->t('Privacy Policy Version'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['version_set']['cookie_policy_version'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cookie Policy Version'),
'#title_display' => 'invisible',
'#description' => $this
->t('Change this value to make the cookie information banner reappear for all visitors. A typical usage of this field is to increase the value when the privacy policy has been changed.'),
'#default_value' => $config
->get('cookie_policy_version') ?: '1.0.0',
'#required' => TRUE,
];
$form['appearance'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Appearance'),
];
$form_color_picker_type = 'textfield';
if ($this->moduleHandler
->moduleExists('jquery_colorpicker')) {
$form_color_picker_type = 'jquery_colorpicker';
$jquery_colorpicker_version = _eu_cookie_compliance_get_jquery_colorpicker_version();
$bg_color = $jquery_colorpicker_version === 2 ? '#' . $config
->get('popup_bg_hex') : $config
->get('popup_bg_hex');
$text_color = $jquery_colorpicker_version === 2 ? '#' . $config
->get('popup_text_hex') : $config
->get('popup_text_hex');
}
else {
$bg_color = $config
->get('popup_bg_hex');
$text_color = $config
->get('popup_text_hex');
}
$form['appearance']['containing_element'] = [
'#type' => 'textfield',
'#title' => $this
->t('Containing element'),
'#default_value' => !empty($config
->get('containing_element')) ? $config
->get('containing_element') : 'body',
'#maxlength' => 255,
'#required' => TRUE,
'#description' => $this
->t('Serves as the parent element to append cookie banner html to.'),
];
$popup_position_options = [
'bottom' => $this
->t('Bottom'),
'top' => $this
->t('Top'),
];
$popup_position_value = $config
->get('popup_position') === TRUE ? 'top' : ($config
->get('popup_position') === FALSE ? 'bottom' : $config
->get('popup_position'));
$form['appearance']['popup_position'] = [
'#type' => 'radios',
'#title' => $this
->t('Position'),
'#default_value' => $popup_position_value,
'#options' => $popup_position_options,
];
$form['appearance']['use_bare_css'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include minimal CSS, I want to style the banner in the theme CSS.'),
'#default_value' => !empty($config
->get('use_bare_css')) ? $config
->get('use_bare_css') : 0,
'#description' => $this
->t('This may be useful if you want the banner to share the button style of your theme. Note that you will have to configure values like the banner width, text color and background color in your CSS file.'),
];
$form['appearance']['popup_text_hex'] = [
'#type' => $form_color_picker_type,
'#title' => $this
->t('Text color'),
'#default_value' => $text_color,
'#description' => $this
->t('Change the text color of the banner. Provide HEX value without the #.'),
'#element_validate' => [
'eu_cookie_compliance_validate_hex',
],
'#states' => [
'visible' => [
"input[name='use_bare_css']" => [
'checked' => FALSE,
],
],
],
];
$form['appearance']['popup_bg_hex'] = [
'#type' => $form_color_picker_type,
'#title' => $this
->t('Background color'),
'#default_value' => $bg_color,
'#description' => $this
->t('Change the background color of the banner. Provide HEX value without the #.'),
'#element_validate' => [
'eu_cookie_compliance_validate_hex',
],
'#states' => [
'visible' => [
"input[name='use_bare_css']" => [
'checked' => FALSE,
],
],
],
];
$form['appearance']['popup_height'] = [
'#type' => 'number',
'#title' => $this
->t('Banner height'),
'#default_value' => !empty($config
->get('popup_height')) ? $config
->get('popup_height') : '',
'#field_suffix' => $this
->t('px'),
'#size' => 5,
'#maxlength' => 5,
'#required' => FALSE,
'#description' => $this
->t('Enter an integer value for a desired height in pixels or leave empty for automatically adjusted height.'),
'#states' => [
'visible' => [
"input[name='use_bare_css']" => [
'checked' => FALSE,
],
],
],
];
$form['appearance']['popup_width'] = [
'#type' => 'textfield',
'#title' => $this
->t('Banner width in pixels or a percentage value'),
'#default_value' => $config
->get('popup_width'),
'#field_suffix' => $this
->t('px or %'),
'#size' => 5,
'#maxlength' => 5,
'#description' => $this
->t('Set the width of the banner. This can be either an integer value or percentage of the screen width. For example: 200 or 50%.'),
'#states' => [
'visible' => [
"input[name='use_bare_css']" => [
'checked' => FALSE,
],
],
'required' => [
"input[name='use_bare_css']" => [
'checked' => FALSE,
],
],
],
];
$form['eu_only'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('EU countries'),
];
if ($this->moduleHandler
->moduleExists('smart_ip') || $this->moduleHandler
->moduleExists('geoip') || extension_loaded('geoip')) {
$form['eu_only']['eu_only'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Only display banner in EU countries.'),
'#default_value' => !empty($config
->get('eu_only')) ? $config
->get('eu_only') : 0,
'#description' => $this
->t('You can limit the number of countries for which the banner is displayed by checking this option. If you want to provide a list of countries other than current EU states, you may place an array in <code>$config[\'eu_cookie_compliance.settings\'][\'eu_countries\']</code> in your <code>settings.php</code> file. Using the <a href="http://drupal.org/project/smart_ip">smart_ip</a> module or using the <a href="http://drupal.org/project/geoip">geoip</a> module or the <a href="http://www.php.net/manual/en/function.geoip-country-code-by-name.php">geoip_country_code_by_name()</a> PHP function.'),
];
$form['eu_only']['eu_only_js'] = [
'#type' => 'checkbox',
'#title' => $this
->t('JavaScript-based (for Varnish): Only display banner in EU countries.'),
'#default_value' => !empty($config
->get('eu_only_js')) ? $config
->get('eu_only_js') : 0,
'#description' => $this
->t('This option also works for visitors that bypass Varnish. You can limit the number of countries for which the banner is displayed by checking this option. If you want to provide a list of countries other than current EU states, you may place an array in <code>$config[\'eu_cookie_compliance.settings\'][\'eu_countries\']</code> in your <code>settings.php</code> file. Using the <a href="http://drupal.org/project/smart_ip">smart_ip</a> module or the <a href="http://www.php.net/manual/en/function.geoip-country-code-by-name.php">geoip_country_code_by_name()</a> PHP function.'),
];
}
else {
$form['eu_only']['info'] = [
'#markup' => $this
->t('You can choose to show the banner only to visitors from EU countries. In order to achieve this, you need to install the <a href="http://drupal.org/project/smart_ip">smart_ip</a> module or install the <a href="http://drupal.org/project/geoip">geoip</a> module or enable the <a href="http://www.php.net/manual/en/function.geoip-country-code-by-name.php">geoip_country_code_by_name()</a> PHP function.'),
];
}
$form['advanced'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this
->t('Advanced'),
];
$form['advanced']['fixed_top_position'] = [
'#type' => 'checkbox',
'#title' => $this
->t("If the banner is at the top, don't scroll the banner with the page."),
'#default_value' => $config
->get('fixed_top_position'),
'#description' => $this
->t('Use position:fixed for the banner when displayed at the top.'),
];
$form['advanced']['accessibility_focus'] = [
'#type' => 'checkbox',
'#title' => 'Buttons have red focus outline (for accessibility)',
'#default_value' => $config
->get('accessibility_focus'),
];
$form['advanced']['popup_delay'] = [
'#type' => 'number',
'#title' => $this
->t('Banner sliding animation time'),
'#default_value' => $config
->get('popup_delay'),
'#field_suffix' => $this
->t('ms'),
'#size' => 5,
'#maxlength' => 5,
'#required' => TRUE,
];
$form['advanced']['disagree_do_not_show_popup'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Do not show cookie policy when the user clicks the "Cookie Policy" button.'),
'#default_value' => !empty($config
->get('disagree_do_not_show_popup')) ? $config
->get('disagree_do_not_show_popup') : 0,
'#description' => $this
->t('Enabling this will make it possible to record the fact that the user disagrees without the user having to see the privacy policy.'),
];
$form['advanced']['reload_page'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Reload page after user clicks the "Agree" button.'),
'#default_value' => !empty($config
->get('reload_page')) ? $config
->get('reload_page') : 0,
];
// Adding option to include/exclude routes to reload.
$reload_options = [
0 => $this
->t('Include'),
1 => $this
->t('Exclude'),
];
$form['advanced']['reload_options'] = [
'#type' => 'radios',
'#title' => $this
->t('Include/exclude specified routes for reloading'),
'#default_value' => $config
->get('reload_options'),
'#options' => $reload_options,
'#description' => $this
->t('Specify if you want to include or exclude the listed below routes for reloading the page after agreeing cookies.'),
'#states' => [
'visible' => [
[
'input[name="reload_page"]' => [
'checked' => TRUE,
],
],
],
],
];
$form['advanced']['reload_routes_list'] = [
'#type' => 'textarea',
'#title' => $this
->t('Routes list'),
'#default_value' => $config
->get('reload_routes_list'),
'#description' => $this
->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. Leave blank for reloading all pages. Leave the list empty to reload on all pages. This field does not support url aliases.", [
'%blog' => '/blog',
'%blog-wildcard' => '/blog/*',
]),
'#states' => [
'visible' => [
[
'input[name="reload_page"]' => [
'checked' => TRUE,
],
],
],
],
];
$form['advanced']['popup_scrolling_confirmation'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Consent by scrolling'),
'#default_value' => $config
->get('popup_scrolling_confirmation'),
'#description' => $this
->t('Scrolling makes the visitors to accept the cookie policy. In some countries, like Italy, it is permitted.'),
'#states' => [
'visible' => [
[
'input[name="method"]' => [
'value' => 'default',
],
],
],
],
];
$form['advanced']['cookie_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cookie name'),
'#default_value' => !empty($config
->get('cookie_name')) ? $config
->get('cookie_name') : '',
'#description' => $this
->t('Sets the cookie name that is used to check whether the user has agreed or not. This option is useful when policies change and the user needs to agree again.'),
];
$form['advanced']['cookie_value_disagreed'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cookie value (disagreed)'),
'#default_value' => !empty($config
->get('cookie_value_disagreed')) ? $config
->get('cookie_value_disagreed') : '0',
'#description' => $this
->t('The cookie value which will be set where the user has disagreed.'),
];
$form['advanced']['cookie_value_agreed_show_thank_you'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cookie value (agreed, show thank you banner)'),
'#default_value' => !empty($config
->get('cookie_value_agreed_show_thank_you')) ? $config
->get('cookie_value_agreed_show_thank_you') : '1',
'#description' => $this
->t('The cookie value which will be set where the user has agreed and we will show a thank-you banner.'),
];
$form['advanced']['cookie_value_agreed'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cookie value (agreed)'),
'#default_value' => !empty($config
->get('cookie_value_agreed')) ? $config
->get('cookie_value_agreed') : '2',
'#description' => $this
->t('The cookie value which will be set where the user has agreed.'),
];
// Adding option to add/remove banner on specified domains.
$exclude_domains_option_active = [
0 => $this
->t('Add'),
1 => $this
->t('Remove'),
];
$form['advanced']['domains_option'] = [
'#type' => 'radios',
'#title' => $this
->t('Add/remove banner on specified domains'),
'#default_value' => $config
->get('domains_option'),
'#options' => $exclude_domains_option_active,
'#description' => $this
->t('Specify if you want to add or remove banner on the listed below domains.'),
];
$form['advanced']['domains_list'] = [
'#type' => 'textarea',
'#title' => $this
->t('Domains list'),
'#default_value' => $config
->get('domains_list'),
'#description' => $this
->t('Specify domains with protocol (e.g., http or https). Enter one domain per line.'),
];
$form['advanced']['exclude_paths'] = [
'#type' => 'textarea',
'#title' => $this
->t('Exclude paths'),
'#default_value' => !empty($config
->get('exclude_paths')) ? $config
->get('exclude_paths') : '',
'#description' => $this
->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", [
'%blog' => '/blog',
'%blog-wildcard' => '/blog/*',
'%front' => '<front>',
]),
];
$form['advanced']['exclude_admin_theme'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Exclude admin pages.'),
'#default_value' => $config
->get('exclude_admin_theme'),
];
$form['advanced']['exclude_uid_1'] = [
'#type' => 'checkbox',
'#title' => $this
->t("Don't show the banner for site administrators (including UID 1)."),
'#default_value' => !empty($config
->get('exclude_uid_1')) ? $config
->get('exclude_uid_1') : 0,
];
$form['advanced']['better_support_for_screen_readers'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Let screen readers see the banner before other links on the page.'),
'#default_value' => !empty($config
->get('better_support_for_screen_readers')) ? $config
->get('better_support_for_screen_readers') : 0,
'#description' => $this
->t('Enable this if you want to place the banner as the first HTML element on the page. This will make it possible for screen readers to close the banner without tabbing through all links on the page.'),
];
$form['advanced']['cookie_session'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Prompt for consent (from the same user) at every new browser session.'),
'#description' => $this
->t("This sets cookie lifetime to 0, invalidating the cookie at the end of the browser session. To set a cookie lifetime greater than 0, uncheck this option. Note that some users will find this behavior highly annoying, and it's recommended to double-check with the legal advisor whether you really need this option enabled."),
'#default_value' => $config
->get('cookie_session'),
];
$form['advanced']['domain'] = [
'#type' => 'textfield',
'#title' => $this
->t('Domain'),
'#default_value' => $config
->get('domain'),
'#description' => $this
->t('Sets the domain of the cookie to a specific url. Used when you need consistency across domains. This is language independent. Note: Make sure you actually enter a domain that the browser can make use of. For example if your site is accessible at both www.domain.com and domain.com, you will not be able to hide the banner at domain.com if your value for this field is www.domain.com.'),
];
$form['advanced']['domain_all_sites'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow the cookie to be set for all sites on the same domain.'),
'#default_value' => !empty($config
->get('domain_all_sites')) ? $config
->get('domain_all_sites') : 0,
'#description' => $this
->t("Sets the path of the cookie to '/' so that the cookie works across all sites on the domain."),
];
$form['advanced']['set_cookie_session_zero_on_disagree'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Set cookie lifetime to 0 if the user clicks the "Decline" or the "Withdraw consent" button.'),
'#description' => $this
->t('Enable this if you want to show the consent banner at every new session until the user clicks the "Agree" button.'),
'#default_value' => $config
->get('set_cookie_session_zero_on_disagree'),
];
$form['advanced']['cookie_lifetime'] = [
'#type' => 'number',
'#title' => $this
->t('Cookie lifetime'),
'#description' => $this
->t("How many days the system remember the user's choice."),
'#default_value' => $config
->get('cookie_lifetime'),
'#field_suffix' => $this
->t('days'),
'#size' => 5,
'#maxlength' => 5,
'#required' => TRUE,
'#states' => [
'enabled' => [
"input[name='cookie_session']" => [
'checked' => FALSE,
],
],
],
];
$form['#attached']['library'][] = 'eu_cookie_compliance/admin';
return parent::buildForm($form, $form_state);
}