Skip to content

Commit 67893fa

Browse files
author
Walther Lalk
committed
Add asset to includedAssets after url is resolved
1 parent 2e3e33a commit 67893fa

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/View/Helper/HtmlHelper.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ class HtmlHelper extends Helper {
9191
*
9292
* @var array
9393
*/
94-
protected $_includedAssets = array(
95-
'css' => array(),
96-
'script' => array()
97-
);
94+
protected $_includedAssets = array();
9895

9996
/**
10097
* Options for the currently opened script block buffer if any.
@@ -408,19 +405,19 @@ public function css($path, array $options = array()) {
408405
return;
409406
}
410407

411-
if ($options['once'] && isset($this->_includedAssets['css'][$path])) {
412-
return '';
413-
}
414-
unset($options['once']);
415-
$this->_includedAssets['css'][$path] = true;
416-
417408
if (strpos($path, '//') !== false) {
418409
$url = $path;
419410
} else {
420411
$url = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.cssBaseUrl'), 'ext' => '.css'));
421412
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
422413
}
423414

415+
if ($options['once'] && isset($this->_includedAssets[$url])) {
416+
return '';
417+
}
418+
unset($options['once']);
419+
$this->_includedAssets[$url] = true;
420+
424421
if ($options['rel'] === 'import') {
425422
$out = $this->formatTemplate('style', [
426423
'attrs' => $this->templater()->formatAttributes($options, ['rel', 'block']),
@@ -492,15 +489,17 @@ public function script($url, array $options = array()) {
492489
}
493490
return null;
494491
}
495-
if ($options['once'] && isset($this->_includedAssets['script'][$url])) {
496-
return null;
497-
}
498-
$this->_includedAssets['script'][$url] = true;
499492

500493
if (strpos($url, '//') === false) {
501494
$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));
502495
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
503496
}
497+
498+
if ($options['once'] && isset($this->_includedAssets[$url])) {
499+
return null;
500+
}
501+
$this->_includedAssets[$url] = true;
502+
504503
$out = $this->formatTemplate('javascriptlink', [
505504
'url' => $url,
506505
'attrs' => $this->templater()->formatAttributes($options, ['block', 'once']),

tests/TestCase/View/Helper/HtmlHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public function testCssLink() {
515515
);
516516
$this->assertTags($result, $expected);
517517

518-
$result = $this->Html->css('screen.css');
518+
$result = $this->Html->css('screen.css', array('once' => false));
519519
$this->assertTags($result, $expected);
520520

521521
Plugin::load('TestPlugin');

0 commit comments

Comments
 (0)