Skip to content

Commit 21d9fff

Browse files
committed
Converting variables to config, changing instances of drupal to backdrop in code, and fixing tests.
1 parent f2419cd commit 21d9fff

File tree

10 files changed

+552
-518
lines changed

10 files changed

+552
-518
lines changed

config/matomo.settings.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"_config_name": "matomo.settings",
3+
"site_id": "",
4+
"url_http": "",
5+
"url_https": "",
6+
"domain_mode": 0,
7+
"visibility_pages": 0,
8+
"visibility_roles": 0,
9+
"roles": [],
10+
"custom": 1,
11+
"trackuserid": 0,
12+
"trackmailto": 1,
13+
"track": 1,
14+
"trackfiles_extensions": "7z|aac|arc|arj|asf|asx|avi|bin|csv|doc(x|m)?|dot(x|m)?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt(x|m)?|pot(x|m)?|pps(x|m)?|ppam|sld(x|m)?|thmx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls(x|m|b)?|xlt(x|m)|xlam|xml|z|zip",
15+
"trackcolorbox": 1,
16+
"trackmessages": [],
17+
"site_search": false,
18+
"privacy_donottrack": 1,
19+
"page_title_hierarchy": false,
20+
"page_title_hierarchy_exclude_home": true,
21+
"custom_var": [],
22+
"cache": 0,
23+
"last_cache": 0,
24+
"translation_set": 0,
25+
"codesnippet_before": "",
26+
"codesnippet_after": "",
27+
"js_scope": "header",
28+
"pages": "admin\nadmin/*\nbatch\nnode/add*\nnode/*/*\nuser/*/*"
29+
}

matomo.admin.inc

Lines changed: 107 additions & 104 deletions
Large diffs are not rendered by default.

matomo.admin.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,116 +3,116 @@
33
/**
44
* Provide the summary information for the tracking settings vertical tabs.
55
*/
6-
Drupal.behaviors.trackingSettingsSummary = {
6+
Backdrop.behaviors.trackingSettingsSummary = {
77
attach: function (context) {
8-
// Make sure this behavior is processed only if drupalSetSummary is defined.
9-
if (typeof jQuery.fn.drupalSetSummary == 'undefined') {
8+
// Make sure this behavior is processed only if backdropSetSummary is defined.
9+
if (typeof jQuery.fn.backdropSetSummary == 'undefined') {
1010
return;
1111
}
1212

13-
$('fieldset#edit-domain-tracking', context).drupalSetSummary(function (context) {
13+
$('fieldset#edit-domain-tracking', context).backdropSetSummary(function (context) {
1414
var $radio = $('input[name="matomo_domain_mode"]:checked', context);
1515
if ($radio.val() == 0) {
16-
return Drupal.t('A single domain');
16+
return Backdrop.t('A single domain');
1717
}
1818
else if ($radio.val() == 1) {
19-
return Drupal.t('One domain with multiple subdomains');
19+
return Backdrop.t('One domain with multiple subdomains');
2020
}
2121
});
2222

23-
$('fieldset#edit-page-vis-settings', context).drupalSetSummary(function (context) {
23+
$('fieldset#edit-page-vis-settings', context).backdropSetSummary(function (context) {
2424
var $radio = $('input[name="matomo_visibility_pages"]:checked', context);
2525
if ($radio.val() == 0) {
2626
if (!$('textarea[name="matomo_pages"]', context).val()) {
27-
return Drupal.t('Not restricted');
27+
return Backdrop.t('Not restricted');
2828
}
2929
else {
30-
return Drupal.t('All pages with exceptions');
30+
return Backdrop.t('All pages with exceptions');
3131
}
3232
}
3333
else {
34-
return Drupal.t('Restricted to certain pages');
34+
return Backdrop.t('Restricted to certain pages');
3535
}
3636
});
3737

38-
$('fieldset#edit-role-vis-settings', context).drupalSetSummary(function (context) {
38+
$('fieldset#edit-role-vis-settings', context).backdropSetSummary(function (context) {
3939
var vals = [];
4040
$('input[type="checkbox"]:checked', context).each(function () {
4141
vals.push($.trim($(this).next('label').text()));
4242
});
4343
if (!vals.length) {
44-
return Drupal.t('Not restricted');
44+
return Backdrop.t('Not restricted');
4545
}
4646
else if ($('input[name="matomo_visibility_roles"]:checked', context).val() == 1) {
47-
return Drupal.t('Excepted: @roles', {'@roles' : vals.join(', ')});
47+
return Backdrop.t('Excepted: @roles', {'@roles' : vals.join(', ')});
4848
}
4949
else {
5050
return vals.join(', ');
5151
}
5252
});
5353

54-
$('fieldset#edit-user-vis-settings', context).drupalSetSummary(function (context) {
54+
$('fieldset#edit-user-vis-settings', context).backdropSetSummary(function (context) {
5555
var $radio = $('input[name="matomo_custom"]:checked', context);
5656
if ($radio.val() == 0) {
57-
return Drupal.t('Not customizable');
57+
return Backdrop.t('Not customizable');
5858
}
5959
else if ($radio.val() == 1) {
60-
return Drupal.t('On by default with opt out');
60+
return Backdrop.t('On by default with opt out');
6161
}
6262
else {
63-
return Drupal.t('Off by default with opt in');
63+
return Backdrop.t('Off by default with opt in');
6464
}
6565
});
6666

67-
$('fieldset#edit-linktracking', context).drupalSetSummary(function (context) {
67+
$('fieldset#edit-linktracking', context).backdropSetSummary(function (context) {
6868
var vals = [];
6969
if ($('input#edit-matomo-trackmailto', context).is(':checked')) {
70-
vals.push(Drupal.t('Mailto links'));
70+
vals.push(Backdrop.t('Mailto links'));
7171
}
7272
if ($('input#edit-matomo-track', context).is(':checked')) {
73-
vals.push(Drupal.t('Outbound links'));
74-
vals.push(Drupal.t('Downloads'));
73+
vals.push(Backdrop.t('Outbound links'));
74+
vals.push(Backdrop.t('Downloads'));
7575
}
7676
if ($('input#edit-matomo-trackcolorbox', context).is(':checked')) {
77-
vals.push(Drupal.t('Colorbox'));
77+
vals.push(Backdrop.t('Colorbox'));
7878
}
7979
if (!vals.length) {
80-
return Drupal.t('Not tracked');
80+
return Backdrop.t('Not tracked');
8181
}
82-
return Drupal.t('@items enabled', {'@items' : vals.join(', ')});
82+
return Backdrop.t('@items enabled', {'@items' : vals.join(', ')});
8383
});
8484

85-
$('fieldset#edit-messagetracking', context).drupalSetSummary(function (context) {
85+
$('fieldset#edit-messagetracking', context).backdropSetSummary(function (context) {
8686
var vals = [];
8787
$('input[type="checkbox"]:checked', context).each(function () {
8888
vals.push($.trim($(this).next('label').text()));
8989
});
9090
if (!vals.length) {
91-
return Drupal.t('Not tracked');
91+
return Backdrop.t('Not tracked');
9292
}
93-
return Drupal.t('@items enabled', {'@items' : vals.join(', ')});
93+
return Backdrop.t('@items enabled', {'@items' : vals.join(', ')});
9494
});
9595

96-
$('fieldset#edit-search', context).drupalSetSummary(function (context) {
96+
$('fieldset#edit-search', context).backdropSetSummary(function (context) {
9797
var vals = [];
9898
if ($('input#edit-matomo-site-search', context).is(':checked')) {
99-
vals.push(Drupal.t('Site search'));
99+
vals.push(Backdrop.t('Site search'));
100100
}
101101
if (!vals.length) {
102-
return Drupal.t('Not tracked');
102+
return Backdrop.t('Not tracked');
103103
}
104-
return Drupal.t('@items enabled', {'@items' : vals.join(', ')});
104+
return Backdrop.t('@items enabled', {'@items' : vals.join(', ')});
105105
});
106106

107-
$('fieldset#edit-privacy', context).drupalSetSummary(function (context) {
107+
$('fieldset#edit-privacy', context).backdropSetSummary(function (context) {
108108
var vals = [];
109109
if ($('input#edit-matomo-privacy-donottrack', context).is(':checked')) {
110-
vals.push(Drupal.t('Universal web tracking opt-out'));
110+
vals.push(Backdrop.t('Universal web tracking opt-out'));
111111
}
112112
if (!vals.length) {
113-
return Drupal.t('No privacy');
113+
return Backdrop.t('No privacy');
114114
}
115-
return Drupal.t('@items enabled', {'@items' : vals.join(', ')});
115+
return Backdrop.t('@items enabled', {'@items' : vals.join(', ')});
116116
});
117117
}
118118
};

matomo.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Matomo Analytics"
22
description = Adds Matomo javascript tracking code to all your site's pages.
3-
core = 7.x
3+
backdrop = 1.x
44
package = Statistics
55
configure = admin/config/system/matomo
66
files[] = matomo.test

matomo.install

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,14 @@
66
*/
77

88
function matomo_install() {
9-
// Remove tracking from all administrative pages, see https://drupal.org/node/34970.
10-
variable_set('matomo_visibility_roles', 0);
11-
variable_set('matomo_visibility_pages', 0);
12-
$pages = array(
13-
'admin',
14-
'admin/*',
15-
'batch',
16-
'node/add*',
17-
'node/*/*',
18-
'user/*/*',
19-
);
20-
variable_set('matomo_pages', implode("\n", $pages));
21-
229
// Make the default install more user and GDPR friendly.
23-
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('opt-in or out of matomo tracking'));
24-
drupal_set_message(t('Module %module granted %permission permission to authenticated users.', array('%module' => 'Matomo Analytics', '%permission' => t('Opt-in or out of tracking'))), 'status');
10+
user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, array('opt-in or out of matomo tracking'));
11+
backdrop_set_message(t('Module %module granted %permission permission to authenticated users.', array('%module' => 'Matomo Analytics', '%permission' => t('Opt-in or out of tracking'))), 'status');
2512
}
2613

2714
function matomo_uninstall() {
28-
variable_del('matomo_cache');
29-
variable_del('matomo_codesnippet_before');
30-
variable_del('matomo_codesnippet_after');
31-
variable_del('matomo_custom');
32-
variable_del('matomo_custom_var');
33-
variable_del('matomo_domain_mode');
34-
variable_del('matomo_js_scope');
35-
variable_del('matomo_last_cache');
36-
variable_del('matomo_page_title_hierarchy');
37-
variable_del('matomo_page_title_hierarchy_exclude_home');
38-
variable_del('matomo_pages');
39-
variable_del('matomo_privacy_donottrack');
40-
variable_del('matomo_roles');
41-
variable_del('matomo_site_id');
42-
variable_del('matomo_site_search');
43-
variable_del('matomo_trackcolorbox');
44-
variable_del('matomo_trackmailto');
45-
variable_del('matomo_track'); // interrims solution
46-
variable_del('matomo_trackfiles_extensions');
47-
variable_del('matomo_trackmessages');
48-
variable_del('matomo_trackuserid');
49-
variable_del('matomo_translation_set');
50-
variable_del('matomo_url_http');
51-
variable_del('matomo_url_https');
52-
variable_del('matomo_visibility_pages');
53-
variable_del('matomo_visibility_roles');
54-
55-
// Remove backup variables if exits. Remove this code in D8.
56-
variable_del('matomo_codesnippet_before_backup_7202');
57-
variable_del('matomo_codesnippet_after_backup_7202');
15+
$config = config('matomo.settings');
16+
$config->delete();
5817
}
5918

6019
/**
@@ -84,7 +43,7 @@ function matomo_requirements($phase) {
8443
}
8544

8645
// Raise warning if Matomo user account has not been set yet.
87-
if (!preg_match('/^\d{1,}$/', variable_get('matomo_site_id', ''))) {
46+
if (!preg_match('/^\d{1,}$/', config_get('matomo.settings', 'site_id'))) {
8847
$requirements['matomo'] = array(
8948
'title' => $t('Matomo module'),
9049
'description' => $t('Matomo module has not been configured yet. Please configure its settings from the <a href="@url">Matomo settings page</a>.', array('@url' => url('admin/config/system/matomo'))),
@@ -98,5 +57,44 @@ function matomo_requirements($phase) {
9857
}
9958

10059
/**
101-
* NOTE: Next update need to be 7206 or updates for 'dev' users may break.
60+
* Move Matomo settings from variables to config.
10261
*/
62+
function matomo_update_1000() {
63+
$config = config('matomo.settings');
64+
65+
$settings = array(
66+
'site_id',
67+
'url_http',
68+
'url_https',
69+
'domain_mode',
70+
'visibility_pages',
71+
'visibility_roles',
72+
'roles',
73+
'custom',
74+
'trackuserid',
75+
'trackmailto',
76+
'track',
77+
'trackfiles_extensions',
78+
'trackcolorbox',
79+
'trackmessages',
80+
'site_search',
81+
'privacy_donottrack',
82+
'page_title_hierarchy',
83+
'page_title_hierarchy_exclude_home',
84+
'custom_var',
85+
'cache',
86+
'last_cache',
87+
'translation_set',
88+
'codesnippet_before',
89+
'codesnippet_after',
90+
'js_scope',
91+
'pages',
92+
);
93+
94+
foreach ($settings as $setting_name) {
95+
$config->set($setting_name, update_variable_get('matomo_' . $setting_name));
96+
update_variable_del('matomo_' . $setting_name);
97+
}
98+
99+
$config->save();
100+
}

matomo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $(document).ready(function() {
99
// Catch the closest surrounding link of a clicked element.
1010
$(event.target).closest("a,area").each(function() {
1111

12-
if (Drupal.settings.matomo.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
12+
if (Backdrop.settings.matomo.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
1313
// Mailto link clicked.
1414
_paq.push(["trackEvent", "Mails", "Click", this.href.substring(7)]);
1515
}
@@ -19,7 +19,7 @@ $(document).ready(function() {
1919

2020
// Colorbox: This event triggers when the transition has completed and the
2121
// newly loaded content has been revealed.
22-
if (Drupal.settings.matomo.trackColorbox) {
22+
if (Backdrop.settings.matomo.trackColorbox) {
2323
$(document).bind("cbox_complete", function () {
2424
var href = $.colorbox.element().attr("href");
2525
if (href) {

0 commit comments

Comments
 (0)