Skip to content

Commit

Permalink
ENGCOM-8223: #1833: Add ability to disable renditions functionality t…
Browse files Browse the repository at this point in the history
…o stores configuration #30057
  • Loading branch information
gabrieldagama authored Sep 21, 2020
2 parents 390505a + 95ba128 commit 7534dbc
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 6 deletions.
13 changes: 12 additions & 1 deletion app/code/Magento/MediaGalleryRenditions/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
class Config
{
private const TABLE_CORE_CONFIG_DATA = 'core_config_data';
private const XML_PATH_ENABLED = 'system/media_gallery/enabled';
private const XML_PATH_MEDIA_GALLERY_ENABLED = 'system/media_gallery/enabled';
private const XML_PATH_ENABLED = 'system/media_gallery_renditions/enabled';
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH = 'system/media_gallery_renditions/width';
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH = 'system/media_gallery_renditions/height';

Expand Down Expand Up @@ -49,6 +50,16 @@ public function __construct(
*
* @return bool
*/
public function isMediaGalleryEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_MEDIA_GALLERY_ENABLED);
}

/**
* Should the renditions be inserted in the content instead of original image
*
* @return bool
*/
public function isEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function beforeExecute(
$storeId
];

if (!$this->config->isEnabled()) {
if (!$this->config->isEnabled() || !$this->config->isMediaGalleryEnabled()) {
return $arguments;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
namespace Magento\MediaGalleryRenditions\Plugin;

use Magento\Framework\App\Config\Value;
use Magento\MediaGalleryRenditions\Model\Config;
use Magento\MediaGalleryRenditions\Model\Queue\ScheduleRenditionsUpdate;

/**
* Update renditions if corresponding configuration changes
*/
class UpdateRenditionsOnConfigChange
{
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH = 'system/media_gallery_renditions/enabled';
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH = 'system/media_gallery_renditions/width';
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH = 'system/media_gallery_renditions/height';

Expand All @@ -24,10 +26,17 @@ class UpdateRenditionsOnConfigChange
private $scheduleRenditionsUpdate;

/**
* @var Config
*/
private $config;

/**
* @param Config $config
* @param ScheduleRenditionsUpdate $scheduleRenditionsUpdate
*/
public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
public function __construct(Config $config, ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
{
$this->config = $config;
$this->scheduleRenditionsUpdate = $scheduleRenditionsUpdate;
}

Expand All @@ -41,7 +50,13 @@ public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
*/
public function afterSave(Value $config, Value $result): Value
{
if ($this->isRenditionsValue($result) && $result->isValueChanged()) {
if ($this->isRenditionsEnabled($result)) {
$this->scheduleRenditionsUpdate->execute();

return $result;
}

if ($this->config->isEnabled() && $this->isRenditionsValue($result) && $result->isValueChanged()) {
$this->scheduleRenditionsUpdate->execute();
}

Expand All @@ -59,4 +74,17 @@ private function isRenditionsValue(Value $value): bool
return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH
|| $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH;
}

/**
* Determine if media gallery renditions is enabled based on configuration value
*
* @param Value $value
* @return bool
*/
private function isRenditionsEnabled(Value $value): bool
{
return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH
&& $value->isValueChanged()
&& $value->getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
<section id="system">
<group id="media_gallery_renditions" translate="label" type="text" sortOrder="1010" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Media Gallery Image Optimization</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enable Image Optimization</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<comment>Resize images to improve performance and decrease the file size. When you use an image from Media Gallery on the storefront, the smaller image is generated and placed instead of the original.
Changing these settings will update all generated images.</comment>
<field id="width" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="width" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Maximum Width</label>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Enter the maximum width of an image in pixels.</comment>
</field>
<field id="height" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="height" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Maximum Height</label>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Enter the maximum height of an image in pixels.</comment>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/MediaGalleryRenditions/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<default>
<system>
<media_gallery_renditions>
<enabled>1</enabled>
<width>1000</width>
<height>1000</height>
</media_gallery_renditions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminMediaGalleryRenditionsEnableActionGroup">
<arguments>
<argument name="enabled" type="string" defaultValue="{{MediaGalleryRenditionsDataEnabled.value}}"/>
</arguments>
<amOnPage url="{{AdminMediaGalleryConfigSystemPage.url}}" stepKey="navigateToSystemConfigurationPage" />
<waitForPageLoad stepKey="waitForPageLoad"/>
<scrollTo selector="{{AdminConfigSystemSection.mediaGalleryRenditionsFieldset}}" stepKey="scrollToMediaGalleryRenditionsFieldset"/>
<conditionalClick stepKey="expandMediaGalleryRenditionsTab" selector="{{AdminConfigSystemSection.mediaGalleryRenditionsFieldset}}" dependentSelector="{{AdminConfigSystemSection.mediaGalleryRenditionsEnabledField}}" visible="false" />
<waitForElementVisible selector="{{AdminConfigSystemSection.mediaGalleryRenditionsFieldset}}" stepKey="waitForFieldset" />
<selectOption userInput="{{enabled}}" selector="{{AdminConfigSystemSection.mediaGalleryRenditionsEnabledField}}" stepKey="enableOrDisableMediaGalleryRenditions"/>
<click selector="{{AdminConfigSystemSection.saveConfig}}" stepKey="saveConfiguration"/>
<waitForPageLoad stepKey="waitForConfigurationToSave"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@
<data key="path">system/media_gallery/enabled</data>
<data key="value">0</data>
</entity>
<entity name="MediaGalleryRenditionsDataEnabled">
<data key="path">system/media_gallery_renditions/enabled</data>
<data key="value">1</data>
</entity>
<entity name="MediaGalleryRenditionsDataDisabled">
<data key="path">system/media_gallery_renditions/enabled</data>
<data key="value">0</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<section name="AdminConfigSystemSection">
<element name="enhancedMediaGalleryFieldset" type="block" selector="#system_media_gallery-head"/>
<element name="enhancedMediaGalleryEnabledField" type="select" selector="[data-ui-id='select-groups-media-gallery-fields-enabled-value']"/>
<element name="mediaGalleryRenditionsFieldset" type="block" selector="#system_media_gallery_renditions-head"/>
<element name="mediaGalleryRenditionsEnabledField" type="select" selector="[data-ui-id='select-groups-media-gallery-renditions-fields-enabled-value']"/>
<element name="saveConfig" type="button" selector="#save"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
<suite name="MediaGalleryUiDisabledSuite">
<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
<actionGroup ref="AdminMediaGalleryRenditionsEnableActionGroup" stepKey="disableMediaGalleryRenditions">
<argument name="enabled" value="0"/>
</actionGroup>
<actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
</before>
<after>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
<actionGroup ref="AdminMediaGalleryRenditionsEnableActionGroup" stepKey="enableMediaGalleryRenditions"/>
</after>
<include>
<group name="media_gallery_ui_disabled"/>
</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<actionGroup ref="AdminMediaGalleryEnhancedEnableActionGroup" stepKey="enableEnhancedMediaGallery">
<argument name="enabled" value="1"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryRenditionsEnableActionGroup" stepKey="enableMediaGalleryRenditions"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
</before>
<after>
Expand Down

0 comments on commit 7534dbc

Please sign in to comment.