Skip to content

Commit 900f558

Browse files
author
Bohdan Berezhniy
committed
added checking on isEnabled
1 parent cb0de46 commit 900f558

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

Plugin/Amasty/PageSpeedOptimizer/Model/Output/LazyLoadProcessorPlugin.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@
88

99
namespace Magefan\LazyLoad\Plugin\Amasty\PageSpeedOptimizer\Model\Output;
1010

11+
use Magefan\LazyLoad\Model\Config;
12+
1113
/**
1214
* Class LazyLoadProcessorPlugin
1315
* @package Magefan\LazyLoad\Plugin\Amasty\PageSpeedOptimizer\Model\Output
1416
*/
1517
class LazyLoadProcessorPlugin
1618
{
19+
/**
20+
* @var Config
21+
*/
22+
private $config;
23+
24+
public function __construct(
25+
Config $config
26+
27+
) {
28+
$this->config = $config;
29+
}
30+
1731
/**
1832
* @param $subject
1933
* @param callable $proceed
@@ -23,6 +37,10 @@ class LazyLoadProcessorPlugin
2337
*/
2438
public function aroundReplaceWithPictureTag($subject, callable $proceed, $image, $imagePath)
2539
{
40+
if (!$this->config->getEnabled()) {
41+
return $proceed($image, $imagePath);
42+
}
43+
2644
$originImagePath = $imagePath;
2745
if (strpos($imagePath, 'Magefan_LazyLoad/images/pixel.jpg')) {
2846

Plugin/Magefan/WebP/Model/WebPPlugin.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
namespace Magefan\LazyLoad\Plugin\Magefan\WebP\Model;
1010

11+
use Magefan\LazyLoad\Model\Config;
1112
use Magefan\WebP\Model\WebP;
13+
use Magento\Framework\Filesystem\Driver\File;
1214

1315
/**
1416
* Class WebPPlugin
@@ -18,20 +20,32 @@ class WebPPlugin
1820
const LAZY_TAG = '<!-- MAGEFAN_LAZY_LOAD -->';
1921

2022
/**
21-
* @var Convertor
23+
* @var WebP
2224
*/
2325
private $webp;
2426

27+
/**
28+
* @var Config
29+
*/
30+
private $config;
31+
2532
public function __construct(
26-
WebP $webp
33+
WebP $webp,
34+
Config $config,
35+
File $fileDriver
2736

2837
) {
2938
$this->webp = $webp;
39+
$this->config = $config;
40+
$this->fileDriver = $fileDriver;
3041
}
3142

3243
public function aroundGetPictureTagHtml($subject, callable $proceed, $webpUrl, $imagePath, $htmlTag)
3344
{
34-
$result = false;
45+
46+
if (!$this->config->getEnabled()) {
47+
return $proceed($webpUrl, $imagePath, $htmlTag);
48+
}
3549

3650
$originImagePath = $imagePath;
3751

@@ -47,13 +61,15 @@ public function aroundGetPictureTagHtml($subject, callable $proceed, $webpUrl, $
4761
$imagePath = substr($htmlTag, $p1, $p2 - $p1);
4862
$webpUrl = $this->webp->getWebpUrl($imagePath);
4963

50-
$result = $this->webp->convert($imagePath, $webpUrl);
51-
5264
}
5365
}
66+
67+
} else {
68+
69+
return $proceed($webpUrl, $imagePath, $htmlTag);
5470
}
5571

56-
if (!$result) {
72+
if (!$this->fileDriver->isExists($this->webp->getPathFromUrl($imagePath))) {
5773
return $htmlTag;
5874
}
5975

0 commit comments

Comments
 (0)