Skip to content

Commit 2ccf3e8

Browse files
Merge branch '1.x-1.x' into harden-info-field-against-xss
2 parents c44da86 + 12015e9 commit 2ccf3e8

4 files changed

Lines changed: 119 additions & 45 deletions

File tree

config/gdpr_cookies.settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"gdpr_cookies_remove_credit": 0,
1010
"gdpr_cookies_default_rejected": 0,
1111
"gdpr_cookies_page_compression": 1,
12-
"gdpr_cookies_privacy_link": ""
12+
"gdpr_cookies_privacy_link": "",
13+
"gdpr_cookies_icon": "default",
14+
"gdpr_cookies_icon_position": "BottomRight"
1315
}

gdpr_cookies.install

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ function gdpr_cookies_uninstall() {
8282
}
8383

8484
/**
85-
* Implements hook_update_N().
86-
*
8785
* Rename table and modify some descriptions.
8886
*/
8987
function gdpr_cookies_update_1001() {
@@ -154,3 +152,16 @@ function gdpr_cookies_update_1001() {
154152
);
155153
db_change_field('gdpr_cookies_service', 'module', 'module', $spec);
156154
}
155+
156+
/**
157+
* Force a rebuild of the GDPR Cookies menu items following fix to menu item
158+
* definition.
159+
*/
160+
function gdpr_cookies_update_1002() {
161+
db_delete('menu_links')
162+
->condition('link_path', '%' . db_like('gdpr-cookies') . '%', 'LIKE')
163+
->condition('module', 'system')
164+
->execute();
165+
menu_cache_clear('management');
166+
cache('admin_bar')->flush();
167+
}

gdpr_cookies.module

Lines changed: 100 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function gdpr_cookies_init() {
1717
backdrop_add_library('gdpr_cookies', 'tarteaucitron', TRUE);
1818

1919
$config = config('gdpr_cookies.settings');
20+
21+
// Get the actual alias path to the privacy policy page from the referenced
22+
// node.
2023
$privacy_link_setting = $config->get('gdpr_cookies_privacy_link');
2124
if (!empty($privacy_link_setting)) {
2225
$nid = gdpr_cookies_node_autocomplete_validate($privacy_link_setting);
@@ -25,17 +28,32 @@ function gdpr_cookies_init() {
2528
else {
2629
$privacy_url = '';
2730
}
31+
32+
// Get the path to the core icons if selected.
33+
$icon_setting = $config->get('gdpr_cookies_icon');
34+
if (!empty($icon_setting) && $icon_setting != 'default') {
35+
$icon_src = '/core/misc/icons/' . $icon_setting . '.svg';
36+
}
37+
else {
38+
$icon_src = '';
39+
}
40+
41+
// Pass the settings to the script.
2842
backdrop_add_js(array(
2943
'gdpr_cookies' => array(
30-
'hashtag' => $config->get('gdpr_cookies_hashtag'),
44+
// Behavior.
3145
'highPrivacy' => $config->get('gdpr_cookies_high_privacy'),
32-
'orientation' => $config->get('gdpr_cookies_orientation'),
46+
'defaultRejected' => $config->get('gdpr_cookies_default_rejected'),
47+
'hashtag' => $config->get('gdpr_cookies_hashtag'),
3348
'adblocker' => $config->get('gdpr_cookies_adblocker'),
49+
// Appearance & Content.
50+
'orientation' => $config->get('gdpr_cookies_orientation'),
51+
'privacyUrl' => $privacy_url,
52+
'iconSrc' => $icon_src,
53+
'iconPosition' => $config->get('gdpr_cookies_icon_position') ?? 'BottomRight',
3454
'showAlertSmall' => $config->get('gdpr_cookies_show_alert_small'),
3555
'cookieslist' => $config->get('gdpr_cookies_cookieslist'),
3656
'removeCredit' => $config->get('gdpr_cookies_remove_credit'),
37-
'defaultRejected' => $config->get('gdpr_cookies_default_rejected'),
38-
'privacyUrl' => $privacy_url,
3957
),
4058
), 'setting');
4159

@@ -113,6 +131,7 @@ function gdpr_cookies_library_info() {
113131
'type' => 'file',
114132
'scope' => 'footer',
115133
'weight' => -4,
134+
'preprocess' => FALSE,
116135
),
117136
backdrop_get_path('module', 'gdpr_cookies') . '/js/init_tarteaucitron.js' => array(
118137
'type' => 'file',
@@ -169,14 +188,19 @@ function gdpr_cookies_permission() {
169188
*/
170189
function gdpr_cookies_menu() {
171190
return array(
172-
'admin/config/system/gdpr-cookies/settings' => array(
173-
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
174-
'title' => 'GDPR Cookies Settings',
191+
'admin/config/system/gdpr-cookies' => array(
192+
'type' => MENU_NORMAL_ITEM,
193+
'title' => 'GDPR Cookies',
175194
'description' => 'Configure GDPR Cookies',
176195
'page callback' => 'backdrop_get_form',
177196
'page arguments' => array('gdpr_cookies_settings_page'),
178197
'access arguments' => array('administer gdpr cookies'),
179198
),
199+
'admin/config/system/gdpr-cookies/settings' => array(
200+
'type' => MENU_DEFAULT_LOCAL_TASK,
201+
'title' => 'Settings',
202+
'weight' => -10,
203+
),
180204

181205
'admin/config/system/gdpr-cookies/gdpr-cookies-service/%gdpr_cookies_service/delete' => array(
182206
'title' => 'Delete',
@@ -198,7 +222,7 @@ function gdpr_cookies_menu() {
198222
'title' => 'Add Third Party Service',
199223
'page callback' => 'gdpr_cookies_service_add',
200224
'type' => MENU_NORMAL_ITEM,
201-
'access arguments' => array('edit gdpr_cookies_service entities'),
225+
'access arguments' => array('create gdpr_cookies_service entities'),
202226
),
203227
'admin/config/system/gdpr-cookies/gdpr-cookies-service/%gdpr_cookies_service' => array(
204228
'title' => 'Edit Third Party Service',
@@ -470,21 +494,50 @@ function gdpr_cookies_settings_page() {
470494
$config = config('gdpr_cookies.settings');
471495
$form['#config'] = 'gdpr_cookies.settings';
472496

473-
$form['gdpr_cookies_hashtag'] = array(
497+
$form['behavior'] = array(
498+
'#type' => 'details',
499+
'#summary' => t('Behavior'),
500+
'#details' => t('Configure the behavior of the module and dialogs.'),
501+
'#open' => TRUE,
502+
'#attributes' => array(
503+
'class' => array('description'),
504+
),
505+
);
506+
$form['behavior']['gdpr_cookies_high_privacy'] = array(
507+
'#type' => 'checkbox',
508+
'#title' => t('High Privacy'),
509+
'#description' => t('Disabling the auto consent feature on navigation?'),
510+
'#default_value' => $config->get('gdpr_cookies_high_privacy') ? TRUE : FALSE,
511+
);
512+
$form['behavior']['gdpr_cookies_default_rejected'] = array(
513+
'#type' => 'checkbox',
514+
'#title' => t('Default Rejected'),
515+
'#description' => t('Should all services be rejected by default?'),
516+
'#default_value' => $config->get('gdpr_cookies_default_rejected') ? TRUE : FALSE,
517+
);
518+
$form['behavior']['gdpr_cookies_hashtag'] = array(
474519
'#type' => 'textfield',
475520
'#title' => t('Hashtag'),
476521
'#description' => t('Automatically open the panel with the hashtag.'),
477522
'#default_value' => $config->get('gdpr_cookies_hashtag'),
478523
);
479-
480-
$form['gdpr_cookies_high_privacy'] = array(
524+
$form['behavior']['gdpr_cookies_adblocker'] = array(
481525
'#type' => 'checkbox',
482-
'#title' => t('High Privacy'),
483-
'#description' => t('Disabling the auto consent feature on navigation?'),
484-
'#default_value' => $config->get('gdpr_cookies_high_privacy') ? TRUE : FALSE,
526+
'#title' => t('Ad-Blocker'),
527+
'#description' => t('Display a message if an adblocker is detected.'),
528+
'#default_value' => $config->get('gdpr_cookies_adblocker') ? TRUE : FALSE,
485529
);
486530

487-
$form['gdpr_cookies_orientation'] = array(
531+
$form['appearance'] = array(
532+
'#type' => 'details',
533+
'#summary' => t('Appearance & Content'),
534+
'#details' => t('Configure the appearance and content of the banner and dialog.'),
535+
'#open' => TRUE,
536+
'#attributes' => array(
537+
'class' => array('description'),
538+
),
539+
);
540+
$form['appearance']['gdpr_cookies_orientation'] = array(
488541
'#type' => 'radios',
489542
'#title' => t('Orientation'),
490543
'#description' => t('The orientation of the big banner.'),
@@ -494,50 +547,56 @@ function gdpr_cookies_settings_page() {
494547
'bottom' => t('Bottom'),
495548
),
496549
);
497-
498-
$form['gdpr_cookies_adblocker'] = array(
499-
'#type' => 'checkbox',
500-
'#title' => t('Ad-Blocker'),
501-
'#description' => t('Display a message if an adblocker is detected.'),
502-
'#default_value' => $config->get('gdpr_cookies_adblocker') ? TRUE : FALSE,
550+
$form['appearance']['gdpr_cookies_privacy_link'] = array(
551+
'#title' => t('Privacy policy page'),
552+
'#type' => 'textfield',
553+
'#maxlength' => 512,
554+
'#default_value' => $config->get('gdpr_cookies_privacy_link'),
555+
'#autocomplete_path' => 'gdpr_cookies_node_autocomplete',
503556
);
504-
505-
$form['gdpr_cookies_show_alert_small'] = array(
557+
$form['appearance']['gdpr_cookies_icon'] = array(
558+
'#type' => 'radios',
559+
'#title' => t('Icon after preferences selected'),
560+
'#description' => t('The icon that will show once cookie preference have been set. You will need to clear both the site caches and browser caches to see the change.'),
561+
'#default_value' => $config->get('gdpr_cookies_icon') ?? 'default',
562+
'#options' => array(
563+
'default' => t('Default (Tarte au Citron logo'),
564+
'cookie' => t('Core cookie icon (cookie)'),
565+
'cookie-fill' => t('Core filled cookie icon (cookie-fill)'),
566+
),
567+
);
568+
$form['appearance']['gdpr_cookies_icon_position'] = array(
569+
'#type' => 'radios',
570+
'#title' => t('Icon position'),
571+
'#description' => t('The position of the icon. You may need to change the position if you enable "Show Alert Small" below as that will always show on the bottom right.'),
572+
'#default_value' => $config->get('gdpr_cookies_icon_position') ?? 'BottomRight',
573+
'#options' => array(
574+
'BottomRight' => t('Bottom right'),
575+
'BottomLeft' => t('Bottom left'),
576+
'TopRight' => t('Top right'),
577+
'TopLeft' => t('Top left'),
578+
),
579+
);
580+
$form['appearance']['gdpr_cookies_show_alert_small'] = array(
506581
'#type' => 'checkbox',
507582
'#title' => t('Show Alert Small'),
508583
'#description' => t('Show the small banner on bottom right?'),
509584
'#default_value' => $config->get('gdpr_cookies_show_alert_small') ? TRUE : FALSE,
510585
);
511586

512-
$form['gdpr_cookies_cookieslist'] = array(
587+
$form['appearance']['gdpr_cookies_cookieslist'] = array(
513588
'#type' => 'checkbox',
514589
'#title' => t('Cookies List'),
515590
'#description' => t('Display the list of cookies installed?'),
516591
'#default_value' => $config->get('gdpr_cookies_cookieslist') ? TRUE : FALSE,
517592
);
518-
519-
$form['gdpr_cookies_remove_credit'] = array(
593+
$form['appearance']['gdpr_cookies_remove_credit'] = array(
520594
'#type' => 'checkbox',
521595
'#title' => t('Remove Credit'),
522596
'#description' => t('Remove the credit link?'),
523597
'#default_value' => $config->get('gdpr_cookies_remove_credit') ? TRUE : FALSE,
524598
);
525599

526-
$form['gdpr_cookies_default_rejected'] = array(
527-
'#type' => 'checkbox',
528-
'#title' => t('Default Rejected'),
529-
'#description' => t('Should all services be rejected by default?'),
530-
'#default_value' => $config->get('gdpr_cookies_default_rejected') ? TRUE : FALSE,
531-
);
532-
533-
$form['gdpr_cookies_privacy_link'] = array(
534-
'#title' => t('Privacy policy page'),
535-
'#type' => 'textfield',
536-
'#maxlength' => 512,
537-
'#default_value' => $config->get('gdpr_cookies_privacy_link'),
538-
'#autocomplete_path' => 'gdpr_cookies_node_autocomplete',
539-
);
540-
541600
$form = system_settings_form($form);
542601
return $form;
543602
}

js/init_tarteaucitron.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ tarteaucitron.init({
77
"cookieslist": Boolean(Backdrop.settings.gdpr_cookies.cookieslist), /* Display the list of cookies installed ? */
88
"removeCredit": Boolean(Backdrop.settings.gdpr_cookies.removeCredit), /* remove the credit link? */
99
"defaultRejected": Boolean(Backdrop.settings.gdpr_cookies.defaultRejected), /* Should the services be rejected by default? */
10-
"privacyUrl": Backdrop.settings.gdpr_cookies.privacyUrl /* Privacy policy url */
10+
"privacyUrl": Backdrop.settings.gdpr_cookies.privacyUrl, /* Privacy policy url */
11+
"iconSrc": Backdrop.settings.gdpr_cookies.iconSrc, /* Optional: URL or base64 encoded image */
12+
"iconPosition": Backdrop.settings.gdpr_cookies.iconPosition /* Position of the icon between BottomRight, BottomLeft, TopRight and TopLeft */
1113
});

0 commit comments

Comments
 (0)