Skip to content

Commit

Permalink
Added font preload support for old Magento versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vovayatsyuk committed Oct 16, 2019
1 parent b6b90be commit 302d01b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Plugin/PageConfigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

class PageConfigRenderer
{
/**
* @var \Magento\Framework\View\Asset\Repository
*/
private $assetRepo;

public function __construct(
\Magento\Framework\View\Asset\Repository $assetRepo
) {
$this->assetRepo = $assetRepo;
}

/**
* Add font preload support in Magento < 2.3.3.
*
Expand Down Expand Up @@ -37,6 +48,20 @@ public function afterRenderAssets(
'rel="preload" as="font" crossorigin="anonymous"',
$link
);

// fix for magento < 2.3.3||2.2.10
if (strpos($newLink, 'href="//') === false &&
strpos($newLink, 'href="http') === false
) {
preg_match('/href="(.*)"/U', $newLink, $href);

if (count($href) > 1) {
$href = $href[1];
$newHref = $this->assetRepo->getUrlWithParams($href, []);
$newLink = str_replace($href, $newHref, $newLink);
}
}

$result = str_replace($link, $newLink, $result);
}

Expand Down

0 comments on commit 302d01b

Please sign in to comment.