@@ -23,7 +23,6 @@ class TemplateMetadata
23
23
public function formatTemplates ($ templates )
24
24
{
25
25
$ byCategory = [];
26
- $ analyticsCategory = [];
27
26
foreach ($ templates as $ template ) {
28
27
if (is_array ($ template )) {
29
28
$ tagArray = $ template ;
@@ -32,16 +31,7 @@ public function formatTemplates($templates)
32
31
}
33
32
34
33
$ category = $ tagArray ['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 ])) {
34
+ if (!isset ($ byCategory [$ category ])) {
45
35
$ byCategory [$ category ] = [
46
36
'name ' => $ category ,
47
37
'types ' => []
@@ -63,26 +53,23 @@ public function formatTemplates($templates)
63
53
return strnatcmp ($ catA ['name ' ], $ catB ['name ' ]);
64
54
});
65
55
66
- $ this ->sortByOrder ($ byCategory );
67
- if (!empty ($ analyticsCategory )) {
68
- $ analyticsCategory = [$ analyticsCategory ];
69
- $ this ->sortByOrder ($ analyticsCategory );
70
-
71
- return array_merge ($ analyticsCategory , $ byCategory );
72
- }
73
-
74
- return $ byCategory ;
75
- }
76
-
77
- private function sortByOrder (&$ categories )
78
- {
79
- foreach ($ categories as &$ category ) {
56
+ foreach ($ byCategory as &$ category ) {
80
57
usort ($ category ['types ' ], function ($ tagA , $ tagB ) {
81
58
if ($ tagA ['order ' ] == $ tagB ['order ' ]) {
82
59
return strnatcmp ($ tagA ['name ' ], $ tagB ['name ' ]);
83
60
}
84
61
return $ tagA ['order ' ] - $ tagB ['order ' ];
85
62
});
86
63
}
64
+
65
+ $ analyticsCategoryName = Piwik::translate ('TagManager_CategoryAnalytics ' );
66
+ $ analyticsCategoryIndex = array_search ($ analyticsCategoryName , array_column ($ byCategory , 'name ' ));
67
+ if (!empty ($ byCategory [$ analyticsCategoryIndex ])) {
68
+ $ analyticsCategory = $ byCategory [$ analyticsCategoryIndex ];
69
+ unset($ byCategory [$ analyticsCategoryIndex ]);
70
+ $ byCategory = array_merge ([$ analyticsCategory ], $ byCategory );
71
+ }
72
+
73
+ return $ byCategory ;
87
74
}
88
75
}
0 commit comments