Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51a79c9

Browse files
committed
Reorder toolbar panels
1 parent 2735346 commit 51a79c9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function getName(Profile $profile, $panel)
7272
public function getTemplates(Profile $profile)
7373
{
7474
$templates = $this->getNames($profile);
75+
$templates = $this->reorderTemplates($templates);
76+
7577
foreach ($templates as $name => $template) {
7678
$templates[$name] = $this->twig->loadTemplate($template);
7779
}
@@ -134,4 +136,47 @@ protected function templateExists($template)
134136

135137
return false;
136138
}
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+
}
137182
}

0 commit comments

Comments
 (0)