Skip to content

Commit fb78f5b

Browse files
Merge pull request #13 from scaleflex/develop
add ignore blocks
2 parents 7928b25 + 96896f1 commit fb78f5b

File tree

8 files changed

+76
-13
lines changed

8 files changed

+76
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [2.0.5] - 2022-08-01
6+
7+
* Support ignore blocks
8+
59
## [2.0.4] - 2022-08-01
610

711
* Support ```params``` options with Library option

Helper/Config.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Config extends AbstractHelper
3737
const XML_PATH_SCALEFLEX_CLOUDIMAGE_ADVANCED_FOTORAMA_COMPATIBILITY = 'scaleflex_cloudimage/advanced/fortorama_compatibility';
3838
const XML_PATH_SCALEFLEX_CLOUDIMAGE_ADVANCED_DEVICEPIXELRATIO = 'scaleflex_cloudimage/advanced/devicepixelratio';
3939
const XML_PATH_SCALEFLEX_CLOUDIMAGE_OPTIONS_ORG_IF_SML = 'scaleflex_cloudimage/advanced/orgifsml';
40+
const XML_PATH_SCALEFLEX_CLOUDIMAGE_IGNORE_BLOCKS = 'scaleflex_cloudimage/advanced/ignore_blocks';
4041

4142
/**
4243
* @return bool
@@ -59,6 +60,29 @@ public function getToken()
5960
);
6061
}
6162

63+
/**
64+
* Get ignore blocks
65+
*
66+
* @return array
67+
*/
68+
public function getIgnoreBlocks()
69+
{
70+
$ignoreList = [];
71+
$ignoreBlocks = $this->scopeConfig->getValue(
72+
self::XML_PATH_SCALEFLEX_CLOUDIMAGE_IGNORE_BLOCKS,
73+
ScopeInterface::SCOPE_STORE
74+
);
75+
if (!empty($ignoreBlocks)) {
76+
$ignoreBlocks = trim($ignoreBlocks);
77+
$explodedBlocks = explode(",", $ignoreBlocks);
78+
foreach ($explodedBlocks as $item) {
79+
$ignoreList[] = trim($item);
80+
}
81+
}
82+
83+
return $ignoreList;
84+
}
85+
6286
/**
6387
* Get Scaleflex Cloudimage plugin configuration
6488
*

Observer/ProcessImages.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ProcessImages implements ObserverInterface
3232
* ProcessImages constructor.
3333
*
3434
* @param Config $config
35-
* @param Images $images
35+
* @param Images $imagesz
3636
*/
3737
public function __construct(
3838
Config $config,
@@ -51,11 +51,41 @@ public function execute(Observer $observer)
5151
return;
5252
}
5353
$transport = $observer->getData('transport');
54+
$block = $observer->getData('block');
55+
56+
if ($this->isIgnoreBlock($block)) {
57+
return;
58+
}
59+
5460
if (stripos($transport->getHtml(), '<img') !== false) {
5561
$newHtml = $this->images->processHtml($transport->getHtml());
5662
if ($transport->getHtml() !== $newHtml) {
5763
$transport->setData('html', $newHtml);
5864
}
5965
}
6066
}
67+
68+
/**
69+
* Check ignored block
70+
* @param $block
71+
* @return bool
72+
*/
73+
private function isIgnoreBlock($block)
74+
{
75+
$blockName = $block->getNameInLayout();
76+
$blockChildNames = $block->getChildNames();
77+
$ignoreBlocks = $this->config->getIgnoreBlocks();
78+
79+
if (in_array($blockName, $ignoreBlocks)) {
80+
return true;
81+
}
82+
83+
foreach ($blockChildNames as $childName) {
84+
if (in_array($childName, $ignoreBlocks)) {
85+
return true;
86+
}
87+
}
88+
89+
return false;
90+
}
6191
}

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ Once the steps listed above are completed enter your Cloudimage token into the S
6464
Stores > Configuration > Cloudimage By Scaleflex > Cloudimage
6565
```
6666

67-
![Scaleflex Cloudimage Plugin Configuration](doc/images/cloudimage_plugin_config_2.0.3.png "Scaleflex Cloudimage Configuration Page")
67+
![Scaleflex Cloudimage Plugin Configuration](doc/images/2.0.5.png "Scaleflex Cloudimage Configuration Page")
6868

6969
Expand the `General` section and activate the module by selecting `Yes` in the `Scaleflex Cloudimage Active` dropdown. Enter your Cloudimage token and configure the Options.
7070

7171
After saving the configuration, you will be asked to flush your Magento cache.
7272

7373
## Options
7474

75-
**(New) Support multiple websites and store views, now you can have difference token for each website.**
75+
**Support multiple websites and store views, now you can have difference token for each website.**
7676

7777
Following options are available:
7878

@@ -102,12 +102,13 @@ This setting is for advanced users only and allows to inject a custom JS functio
102102

103103
**Maximum "Pixel ratio"**: List of supported device pixel ratios, default is 2, eg: 2 for Retina devices
104104

105-
**(New)Prevent Image Resize**: If you set Maximum "Pixel ratio" equal to 2, but some of your assets does not have min retina size(at least 2560x960), please enable this to prevent image resized
105+
**Prevent Image Resize**: If you set Maximum "Pixel ratio" equal to 2, but some of your assets does not have min retina size(at least 2560x960), please enable this to prevent image resized
106106

107107
**Custom Library Options**: Those optional parameters will be added to the request for each URL going through the Cloudimage acceleration infrastructure. It can allow you to force image formats, apply automatic transformations or watermarking, and might be used for troubleshooting purposes. (for advanced users only, please refer to the official [Cloudimage documentation here](https://docs/cloudimage.io) for the list of possible parameters)
108108

109109
**Remove v7**: Removes the "/v7" part in URL format. Activate for token created after October 20th 2021.
110110

111+
**Ignore blocks(New)**: Cloudimage will not affect on these blocks, separate by comma. For example: product.info.description, product.info.attribute.
111112

112113
## 2. Integration "on-the-fly" in Magento templates
113114

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"ext-libxml": "*"
88
},
99
"type": "magento2-module",
10-
"version": "2.0.4",
10+
"version": "2.0.5",
1111
"license": "BSD-3-Clause",
1212
"authors": [
1313
{

doc/images/2.0.5.png

131 KB
Loading

etc/adminhtml/system.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@
8080
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
8181
<comment><![CDATA[By default, yes.]]></comment>
8282
</field>
83-
<field id="fortorama_compatibility" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
84-
<label>Fotorama Compatibility Mode</label>
85-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
86-
<comment><![CDATA[Fotorama compatibility mode, default no]]></comment>
87-
</field>
88-
<field id="devicepixelratio" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
83+
<field id="fortorama_compatibility" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
84+
<label>Fotorama Compatibility Mode</label>
85+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
86+
<comment><![CDATA[Fotorama compatibility mode, default no]]></comment>
87+
</field>
88+
<field id="devicepixelratio" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
8989
<label>Maximum "Pixel ratio"</label>
9090
<source_model>Scaleflex\Cloudimage\Model\Config\Source\PixelRatio</source_model>
9191
<comment><![CDATA[List of supported device pixel ratios, eg: 2 for Retina devices]]></comment>
92-
</field>
92+
</field>
9393
<field id="orgifsml" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
9494
<label>Prevent Image Resize</label>
9595
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
@@ -104,6 +104,10 @@
104104
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
105105
<comment><![CDATA[Removes the "/v7" part in URL format. Activate for token created after October 20th 2021.]]></comment>
106106
</field>
107+
<field id="ignore_blocks" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
108+
<label>Ignore blocks</label>
109+
<comment><![CDATA[Cloudimage will not affect on these blocks, separate by comma. For example: product.info.description, product.info.attribute]]></comment>
110+
</field>
107111
</group>
108112
</section>
109113
</system>

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4-
<module name="Scaleflex_Cloudimage" setup_version="2.0.4">
4+
<module name="Scaleflex_Cloudimage" setup_version="2.0.5">
55
<sequence>
66
<module name="Magento_Catalog"/>
77
</sequence>

0 commit comments

Comments
 (0)