Skip to content

Commit a2551af

Browse files
author
Vasilii
committed
#5023 - It is not possible to add MS tile image meta via default_head_blocks.xml
1 parent 7b1cd79 commit a2551af

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ class Config
130130
'title' => null,
131131
];
132132

133+
/**
134+
* @var array
135+
*/
136+
protected $additionalMetaAssets = ['msapplication-TileImage'];
137+
133138
/**
134139
* @var \Magento\Framework\App\State
135140
*/
@@ -539,6 +544,30 @@ public function addBodyClass($className)
539544
return $this;
540545
}
541546

547+
/**
548+
* Retrieve the additional meta assets
549+
*
550+
* @return array
551+
*/
552+
public function getAdditionalMetaAssets()
553+
{
554+
return $this->additionalMetaAssets;
555+
}
556+
/**
557+
* Adjust metadata content url
558+
*
559+
* @param string $content
560+
* @return string $content
561+
*/
562+
public function getMetaAssetUrl($content)
563+
{
564+
$parsed = parse_url($content);
565+
if (empty($parsed['scheme'])) {
566+
return $this->assetRepo->getUrl($content);
567+
}
568+
return $content;
569+
}
570+
542571
/**
543572
* Set additional element attribute
544573
*

lib/internal/Magento/Framework/View/Page/Config/Renderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ protected function processMetadataContent($name, $content)
157157
if (method_exists($this->pageConfig, $method)) {
158158
$content = $this->pageConfig->$method();
159159
}
160+
if ($content && in_array($name, $this->pageConfig->getAdditionalMetaAssets())) {
161+
$content = $this->pageConfig->getMetaAssetUrl($content);
162+
}
163+
160164
return $content;
161165
}
162166

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ public function testRenderMetadata()
171171
->method('getMetadata')
172172
->will($this->returnValue($metadata));
173173

174+
$this->pageConfigMock
175+
->expects($this->any())
176+
->method('getAdditionalMetaAssets')
177+
->will($this->returnValue(['msapplication-TileImage']));
178+
174179
$this->assertEquals($expected, $this->renderer->renderMetadata());
175180
}
176181

lib/internal/Magento/Framework/View/Test/Unit/Page/ConfigTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ public function testAddRss()
369369
$this->assertInstanceOf(\Magento\Framework\View\Page\Config::class, $this->model->addRss($title, $href));
370370
}
371371

372+
public function testGetMetaAssetUrlWithUrlInContent()
373+
{
374+
$this->assetRepo->expects($this->never())->method('getUrl');
375+
$this->assertEquals('http://test.com/image.png', $this->model->getMetaAssetUrl('http://test.com/image.png'));
376+
}
377+
378+
public function testGetMetaAssetUrlWithoutUrlInContent()
379+
{
380+
$this->assetRepo->expects($this->once())->method('getUrl')->with('image.png')->will(
381+
$this->returnValue('http://test.com/image.png')
382+
);
383+
$this->assertEquals('http://test.com/image.png', $this->model->getMetaAssetUrl('image.png'));
384+
}
385+
372386
public function testAddBodyClass()
373387
{
374388
$className = 'test class';

0 commit comments

Comments
 (0)