Skip to content

Commit e771362

Browse files
authored
Merge pull request #41 from magefan/9997-page-builder-compatibility
add option to exlude image from lazy load
2 parents 2fe12b5 + 38ff225 commit e771362

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-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/di.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magefan ([email protected]). All rights reserved.
5+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
6+
*
7+
* Glory to Ukraine! Glory to the heroes!
8+
*/
9+
-->
10+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
11+
<virtualType name="DefaultWYSIWYGValidator">
12+
<arguments>
13+
<argument name="allowedAttributes" xsi:type="array">
14+
<item name="mfdislazy" xsi:type="string">mfdislazy</item>
15+
</argument>
16+
</arguments>
17+
</virtualType>
18+
</config>

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>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magefan ([email protected]). All rights reserved.
5+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
6+
*
7+
* Glory to Ukraine! Glory to the heroes!
8+
*/
9+
-->
10+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_PageBuilder:etc/content_type.xsd">
11+
<type name="image">
12+
<appearances>
13+
<appearance name="full-width">
14+
<elements>
15+
<element name="desktop_image">
16+
<attribute name="exlude_from_lazy_load" source="mfdislazy"/>
17+
</element>
18+
<element name="mobile_image">
19+
<attribute name="exlude_from_lazy_load" source="mfdislazy"/>
20+
</element>
21+
</elements>
22+
</appearance>
23+
</appearances>
24+
</type>
25+
</config>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magefan ([email protected]). All rights reserved.
5+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
6+
*
7+
* Glory to Ukraine! Glory to the heroes!
8+
*/
9+
-->
10+
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd" extends="pagebuilder_base_form">
11+
<fieldset name="general">
12+
<field name="exlude_from_lazy_load" sortOrder="90">
13+
<argument name="data" xsi:type="array">
14+
<item name="config" xsi:type="array">
15+
<item name="dataType" xsi:type="string">boolean</item>
16+
<item name="label" xsi:type="string" translate="true">Exlude From Lazy Load</item>
17+
<item name="formElement" xsi:type="string">checkbox</item>
18+
<item name="prefer" xsi:type="string">toggle</item>
19+
<item name="dataScope" xsi:type="string">exlude_from_lazy_load</item>
20+
<item name="valueMap" xsi:type="array">
21+
<item name="true" xsi:type="number">1</item>
22+
<item name="false" xsi:type="number">0</item>
23+
</item>
24+
<item name="default" xsi:type="number">1</item>
25+
</item>
26+
</argument>
27+
</field>
28+
</fieldset>
29+
</form>

0 commit comments

Comments
 (0)