@@ -72,6 +72,8 @@ public function getName(Profile $profile, $panel)
72
72
public function getTemplates (Profile $ profile )
73
73
{
74
74
$ templates = $ this ->getNames ($ profile );
75
+ $ templates = $ this ->reorderTemplates ($ templates );
76
+
75
77
foreach ($ templates as $ name => $ template ) {
76
78
$ templates [$ name ] = $ this ->twig ->loadTemplate ($ template );
77
79
}
@@ -134,4 +136,47 @@ protected function templateExists($template)
134
136
135
137
return false ;
136
138
}
139
+
140
+ /**
141
+ * It changes the default order of collector templates to show them in a
142
+ * different order which is better for design and aesthetic reasons.
143
+ *
144
+ * @param array $templates
145
+ * @return array
146
+ */
147
+ protected function reorderTemplates ($ templates )
148
+ {
149
+ $ templates = $ this ->moveArrayElementToFirstPosition ($ templates , 'memory ' );
150
+ $ templates = $ this ->moveArrayElementToFirstPosition ($ templates , 'time ' );
151
+ $ templates = $ this ->moveArrayElementToFirstPosition ($ templates , 'request ' );
152
+
153
+ $ templates = $ this ->moveArrayElementToLastPosition ($ templates , 'config ' );
154
+
155
+ return $ templates ;
156
+ }
157
+
158
+ private function moveArrayElementToFirstPosition ($ array , $ key )
159
+ {
160
+ if (!array_key_exists ($ key , $ array )) {
161
+ return $ array ;
162
+ }
163
+
164
+ $ value = $ array [$ key ];
165
+ unset($ array [$ key ]);
166
+
167
+ return array_merge (array ($ key => $ value ), $ array );
168
+ }
169
+
170
+ private function moveArrayElementToLastPosition ($ array , $ key )
171
+ {
172
+ if (!array_key_exists ($ key , $ array )) {
173
+ return $ array ;
174
+ }
175
+
176
+ $ value = $ array [$ key ];
177
+ unset($ array [$ key ]);
178
+ $ array [$ key ] = $ value ;
179
+
180
+ return $ array ;
181
+ }
137
182
}
0 commit comments