Skip to content

Commit 32726fe

Browse files
Ensure Analytics category is always shown at top, #PG-4052
1 parent a99d240 commit 32726fe

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

API/TemplateMetadata.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TemplateMetadata
2323
public function formatTemplates($templates)
2424
{
2525
$byCategory = [];
26+
$analyticsCategory = [];
2627
foreach ($templates as $template) {
2728
if (is_array($template)) {
2829
$tagArray = $template;
@@ -31,7 +32,16 @@ public function formatTemplates($templates)
3132
}
3233

3334
$category = $tagArray['category'];
34-
if (!isset($byCategory[$category])) {
35+
if ($category === Piwik::translate('TagManager_CategoryAnalytics')) {
36+
if (!isset($analyticsCategory['types'])) {
37+
$analyticsCategory = [
38+
'name' => $category,
39+
'types' => []
40+
];
41+
}
42+
$analyticsCategory['types'][] = $tagArray;
43+
continue;
44+
} elseif (!isset($byCategory[$category])) {
3545
$byCategory[$category] = [
3646
'name' => $category,
3747
'types' => []
@@ -62,6 +72,6 @@ public function formatTemplates($templates)
6272
});
6373
}
6474

65-
return $byCategory;
75+
return $analyticsCategory ? array_merge([$analyticsCategory], $byCategory) : $byCategory;
6676
}
6777
}

Template/Variable/BaseVariable.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ abstract class BaseVariable extends BaseTemplate
3131
public const CATEGORY_DEVICE = 'TagManager_CategoryDevice';
3232
public const CATEGORY_SEO = 'TagManager_CategorySEO';
3333
public const CATEGORY_OTHERS = 'General_Others';
34+
public const CATEGORY_ANALYTICS = 'TagManager_CategoryAnalytics';
3435

3536
protected $templateType = 'Variable';
3637

Template/Variable/MatomoConfigurationVariable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getId()
3232

3333
public function getCategory()
3434
{
35-
return self::CATEGORY_OTHERS;
35+
return self::CATEGORY_ANALYTICS;
3636
}
3737

3838
public function getIcon()

tests/Unit/API/TemplateMetadataTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,32 @@ public function test_formatTemplates_BasedOnArrays()
4242
['category' => 'Baz', 'name' => 'ZooName', 'order' => 10],
4343
['category' => 'Baz', 'name' => 'FooName', 'order' => 10],
4444
['category' => 'Baz', 'name' => 'AooName', 'order' => 10],
45+
['category' => 'A', 'name' => 'First Name', 'order' => 10], // should come after Analytics category
46+
['category' => 'Analytics', 'name' => 'Matomo Configuration', 'order' => 1000], // should be the first category
4547
);
4648
$expected = array (
49+
array (
50+
'name' => 'Analytics',
51+
'types' =>
52+
array (
53+
array (
54+
'category' => 'Analytics',
55+
'name' => 'Matomo Configuration',
56+
'order' => 1000,
57+
),
58+
),
59+
),
60+
array (
61+
'name' => 'A',
62+
'types' =>
63+
array (
64+
array (
65+
'category' => 'A',
66+
'name' => 'First Name',
67+
'order' => 10,
68+
),
69+
),
70+
),
4771
array (
4872
'name' => 'Bar',
4973
'types' =>

0 commit comments

Comments
 (0)