From 4f54e57cdc2ef3635207b285d90ec801e129b048 Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Fri, 28 Nov 2014 03:14:54 -0600 Subject: [PATCH] Fixed AssetsHelper to output declarations in the order they are injected --- .../Templating/Helper/AssetsHelper.php | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/app/bundles/CoreBundle/Templating/Helper/AssetsHelper.php b/app/bundles/CoreBundle/Templating/Helper/AssetsHelper.php index ee45dfc7567..1c8c9d34f5f 100644 --- a/app/bundles/CoreBundle/Templating/Helper/AssetsHelper.php +++ b/app/bundles/CoreBundle/Templating/Helper/AssetsHelper.php @@ -49,10 +49,7 @@ public function addScript($script, $location = 'head') $addScripts = function ($s) use ($location, &$assets) { if ($location == 'head') { //special place for these so that declarations and scripts can be mingled - $assets['headDeclarations'][] = array( - 'type' => 'script', - 'src' => $s - ); + $assets['headDeclarations']['script'][] = $s; } else { if (!isset($assets['scripts'][$location])) { $assets['scripts'][$location] = array(); @@ -85,10 +82,7 @@ public function addScriptDeclaration($script, $location = 'head') { if ($location == 'head') { //special place for these so that declarations and scripts can be mingled - $this->assets['headDeclarations'][] = array( - 'type' => 'declaration', - 'script' => $script - ); + $this->assets['headDeclarations']['declaration'][] = $script; } else { if (!isset($this->assets['scriptDeclarations'][$location])) { $this->assets['scriptDeclarations'][$location] = array(); @@ -141,8 +135,8 @@ public function loadEditor() if (empty($editorLoaded)) { $editorLoaded = true; $this->addScript(array( - 'app/bundles/CoreBundle/Assets/js/libraries/ckeditor/ckeditor.js', - 'app/bundles/CoreBundle/Assets/js/libraries/ckeditor/adapters/jquery.js' + 'app/bundles/CoreBundle/Assets/js/libraries/ckeditor/adapters/jquery.js', + 'app/bundles/CoreBundle/Assets/js/libraries/ckeditor/ckeditor.js' )); } } @@ -176,10 +170,7 @@ public function addStyleDeclaration($styles) public function addCustomDeclaration($declaration, $location = 'head') { if ($location == 'head') { - $this->assets['headDeclarations'][] = array( - 'type' => 'custom', - 'declaration' => $declaration - ); + $this->assets['headDeclarations']['custom'][] = $declaration; } else { if (!isset($this->assets['customDeclarations'][$location])) { $this->assets['customDeclarations'][$location] = array(); @@ -199,14 +190,15 @@ public function addCustomDeclaration($declaration, $location = 'head') public function outputStyles() { if (isset($this->assets['stylesheets'])) { - foreach ($this->assets['stylesheets'] as $s) { + + foreach (array_reverse($this->assets['stylesheets']) as $s) { echo '' . "\n"; } } if (isset($this->assets['styleDeclarations'])) { echo "\n"; @@ -223,21 +215,21 @@ public function outputStyles() public function outputScripts($location) { if (isset($this->assets['scripts'][$location])) { - foreach ($this->assets['scripts'][$location] as $s) { + foreach (array_reverse($this->assets['scripts'][$location]) as $s) { echo ''."\n"; } } if (isset($this->assets['scriptDeclarations'][$location])) { echo "\n"; } if (isset($this->assets['customDeclarations'][$location])) { - foreach ($this->assets['customDeclarations'][$location] as $d) { + foreach (array_reverse($this->assets['customDeclarations'][$location]) as $d) { echo "$d\n"; } } @@ -252,15 +244,24 @@ public function outputHeadDeclarations() { $this->outputStyles(); - if (isset($this->assets['headDeclarations'])) { - foreach ($this->assets['headDeclarations'] as $h) { - if ($h['type'] == 'script') { - echo ''."\n"; - } elseif ($h['type'] == 'declaration') { - echo "\n"; - } else { - echo $h['declaration'] . "\n"; - } + + if (!empty($this->assets['headDeclarations']['script'])) { + foreach (array_reverse($this->assets['headDeclarations']['script']) as $script) { + echo '' . "\n"; + } + } + + if (!empty($this->assets['headDeclarations']['declaration'])) { + echo "\n\n\n"; + } + + if (!empty($this->assets['headDeclarations']['custom'])) { + foreach (array_reverse($this->assets['headDeclarations']['custom']) as $custom) { + echo "\n$custom"; } } }