Skip to content

Commit d3e24ed

Browse files
SerhiyDmytruknmalevanec
authored andcommitted
Fix bug #1821
Added new attribute 'order' for set loading order . Those attribute resolve issue about render files for some order.
1 parent 232eec2 commit d3e24ed

File tree

6 files changed

+79
-34
lines changed

6 files changed

+79
-34
lines changed

lib/internal/Magento/Framework/View/Layout/etc/head.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<xs:attribute name="sizes" type="xs:string"/>
1919
<xs:attribute name="target" type="xs:string"/>
2020
<xs:attribute name="type" type="xs:string"/>
21+
<xs:attribute name="order" type="xs:integer"/>
2122
<xs:attribute name="src_type" type="xs:string"/>
2223
</xs:complexType>
2324

lib/internal/Magento/Framework/View/Page/Config/Generator/Head.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Head implements Layout\GeneratorInterface
4242
*/
4343
protected $assetProperties = [
4444
'ie_condition',
45+
'order'
4546
];
4647

4748
/**

lib/internal/Magento/Framework/View/Page/Config/Reader/Head.php

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,38 +71,49 @@ public function interpret(
7171
Layout\Element $headElement
7272
) {
7373
$pageConfigStructure = $readerContext->getPageConfigStructure();
74-
/** @var \Magento\Framework\View\Layout\Element $node */
74+
75+
$orderedNodes = [];
76+
7577
foreach ($headElement as $node) {
76-
switch ($node->getName()) {
77-
case self::HEAD_CSS:
78-
case self::HEAD_SCRIPT:
79-
case self::HEAD_LINK:
80-
$this->addContentTypeByNodeName($node);
81-
$pageConfigStructure->addAssets($node->getAttribute('src'), $this->getAttributes($node));
82-
break;
83-
84-
case self::HEAD_REMOVE:
85-
$pageConfigStructure->removeAssets($node->getAttribute('src'));
86-
break;
87-
88-
case self::HEAD_TITLE:
89-
$pageConfigStructure->setTitle(new \Magento\Framework\Phrase($node));
90-
break;
91-
92-
case self::HEAD_META:
93-
$this->setMetadata($pageConfigStructure, $node);
94-
break;
95-
96-
case self::HEAD_ATTRIBUTE:
97-
$pageConfigStructure->setElementAttribute(
98-
PageConfig::ELEMENT_TYPE_HEAD,
99-
$node->getAttribute('name'),
100-
$node->getAttribute('value')
101-
);
102-
break;
103-
104-
default:
105-
break;
78+
$nodeOrder = $node->getAttribute('order') ?: 0;
79+
$orderedNodes[$nodeOrder][] = $node;
80+
}
81+
82+
ksort($orderedNodes);
83+
foreach ($orderedNodes as $nodes ) {
84+
/** @var \Magento\Framework\View\Layout\Element $node */
85+
foreach ($nodes as $node) {
86+
switch ($node->getName()) {
87+
case self::HEAD_CSS:
88+
case self::HEAD_SCRIPT:
89+
case self::HEAD_LINK:
90+
$this->addContentTypeByNodeName($node);
91+
$pageConfigStructure->addAssets($node->getAttribute('src'), $this->getAttributes($node));
92+
break;
93+
94+
case self::HEAD_REMOVE:
95+
$pageConfigStructure->removeAssets($node->getAttribute('src'));
96+
break;
97+
98+
case self::HEAD_TITLE:
99+
$pageConfigStructure->setTitle(new \Magento\Framework\Phrase($node));
100+
break;
101+
102+
case self::HEAD_META:
103+
$this->setMetadata($pageConfigStructure, $node);
104+
break;
105+
106+
case self::HEAD_ATTRIBUTE:
107+
$pageConfigStructure->setElementAttribute(
108+
PageConfig::ELEMENT_TYPE_HEAD,
109+
$node->getAttribute('name'),
110+
$node->getAttribute('value')
111+
);
112+
break;
113+
114+
default:
115+
break;
116+
}
106117
}
107118
}
108119
return $this;

lib/internal/Magento/Framework/View/Test/Unit/Page/Config/Generator/HeadTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ public function testProcess()
8282
'content_type' => 'css',
8383
'media' => 'all',
8484
],
85+
'remoteCssOrderedLast' => [
86+
'src' => 'file-url-css-last',
87+
'src_type' => 'url',
88+
'content_type' => 'css',
89+
'media' => 'all',
90+
'order' => 30,
91+
],
92+
'remoteCssOrderedFirst' => [
93+
'src' => 'file-url-css-first',
94+
'src_type' => 'url',
95+
'content_type' => 'css',
96+
'media' => 'all',
97+
'order' => 10,
98+
],
8599
'remoteLink' => [
86100
'src' => 'file-url-link',
87101
'src_type' => 'url',
@@ -106,8 +120,14 @@ public function testProcess()
106120
->with('file-url-css', 'css', ['attributes' => ['media' => 'all']]);
107121
$this->pageConfigMock->expects($this->at(1))
108122
->method('addRemotePageAsset')
109-
->with('file-url-link', Head::VIRTUAL_CONTENT_TYPE_LINK, ['attributes' => ['media' => 'all']]);
123+
->with('file-url-css-last','css', ['attributes' => ['media' => 'all' ] , 'order' => 30]);
110124
$this->pageConfigMock->expects($this->at(2))
125+
->method('addRemotePageAsset')
126+
->with('file-url-css-first','css', ['attributes' => ['media' => 'all'] , 'order' => 10]);
127+
$this->pageConfigMock->expects($this->at(3))
128+
->method('addRemotePageAsset')
129+
->with('file-url-link', Head::VIRTUAL_CONTENT_TYPE_LINK, ['attributes' => ['media' => 'all']]);
130+
$this->pageConfigMock->expects($this->at(4))
111131
->method('addRemotePageAsset')
112132
->with('http://magento.dev/customcss/render/css', 'css', ['attributes' => ['media' => 'all']]);
113133
$this->pageConfigMock->expects($this->once())

lib/internal/Magento/Framework/View/Test/Unit/Page/Config/Reader/HeadTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testInterpret()
5959

6060
$structureMock->expects($this->at(4))
6161
->method('addAssets')
62-
->with('path/file.css', ['src' => 'path/file.css', 'media' => 'all', 'content_type' => 'css'])
62+
->with('path/file-3.css', ['src' => 'path/file-3.css', 'media' => 'all', 'content_type' => 'css'])
6363
->willReturnSelf();
6464

6565
$structureMock->expects($this->at(5))
@@ -82,6 +82,16 @@ public function testInterpret()
8282
->with(Config::ELEMENT_TYPE_HEAD, 'head_attribute_name', 'head_attribute_value')
8383
->willReturnSelf();
8484

85+
$structureMock->expects($this->at(9))
86+
->method('addAssets')
87+
->with('path/file-1.css', ['src' => 'path/file-1.css', 'media' => 'all', 'content_type' => 'css', 'order' => 10])
88+
->willReturnSelf();
89+
90+
$structureMock->expects($this->at(10))
91+
->method('addAssets')
92+
->with('path/file-2.css', ['src' => 'path/file-2.css', 'media' => 'all', 'content_type' => 'css', 'order' => 30])
93+
->willReturnSelf();
94+
8595
$this->assertEquals($this->model, $this->model->interpret($readerContextMock, $element->children()[0]));
8696
}
8797
}

lib/internal/Magento/Framework/View/Test/Unit/Page/Config/_files/template_head.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<meta name="meta_name" content="meta_content"/>
1212
<meta property="og:video:secure_url" content="https://secure.example.com/movie.swf" />
1313
<meta property="og:locale:alternate" content="uk_UA" />
14-
<css src="path/file.css" media="all" />
14+
<css src="path/file-1.css" order="10" media="all" />
15+
<css src="path/file-2.css" order="30" media="all" />
16+
<css src="path/file-3.css" media="all" />
1517
<script src="path/file.js" defer="defer"/>
1618
<link src="http://url.com" src_type="url"/>
1719
<remove src="path/remove/file.css"/>

0 commit comments

Comments
 (0)