Skip to content

Commit 38ff225

Browse files
author
Bohdan Berezhniy
committed
moved mfdislazy attribute direct after <img
1 parent c9d54ba commit 38ff225

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
declare(strict_types = 1);
10+
11+
namespace Magefan\LazyLoad\Plugin\Magento\PageBuilder\Model\Filter;
12+
13+
use Magefan\LazyLoad\Model\Config;
14+
15+
class Template
16+
{
17+
/**
18+
* @var Config
19+
*/
20+
private $config;
21+
22+
/**
23+
* @param Config $config
24+
*/
25+
public function __construct(
26+
Config $config
27+
) {
28+
$this->config = $config;
29+
}
30+
31+
/**
32+
* @param $subject
33+
* @param $result
34+
* @return mixed|string
35+
*/
36+
public function afterFilter($subject, $result)
37+
{
38+
if ($this->config->getEnabled()) {
39+
$this->moveMfDislazyAttributeDirectAfterImg($result);
40+
}
41+
42+
return $result;
43+
}
44+
45+
/**
46+
* @param string $result
47+
* @return void
48+
*/
49+
private function moveMfDislazyAttributeDirectAfterImg(string &$result)
50+
{
51+
if (strpos($result, 'mfdislazy="1"') !== false) {
52+
$result = explode('<img ', $result);
53+
54+
foreach ($result as $key => $imgStart) {
55+
if (strpos($imgStart, 'mfdislazy="1"') !== false) {
56+
$result[$key] = 'mfdislazy="1" ' . str_replace('mfdislazy="1"', '', $imgStart);
57+
}
58+
}
59+
60+
$result = implode('<img ', $result);
61+
}
62+
}
63+
}

etc/frontend/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@
4747
</argument>
4848
</arguments>
4949
</type>
50+
51+
<type name="Magento\PageBuilder\Model\Filter\Template">
52+
<plugin disabled="false" name="move-mfdislazy-direct-after-img" sortOrder="10" type="Magefan\LazyLoad\Plugin\Magento\PageBuilder\Model\Filter\Template"/>
53+
</type>
5054
</config>

0 commit comments

Comments
 (0)