diff --git a/app/code/Magento/MediaGalleryRenditions/Model/Config.php b/app/code/Magento/MediaGalleryRenditions/Model/Config.php index d1a48904d1f13..6622ef36dffd7 100644 --- a/app/code/Magento/MediaGalleryRenditions/Model/Config.php +++ b/app/code/Magento/MediaGalleryRenditions/Model/Config.php @@ -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'; @@ -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); diff --git a/app/code/Magento/MediaGalleryRenditions/Plugin/SetRenditionPath.php b/app/code/Magento/MediaGalleryRenditions/Plugin/SetRenditionPath.php index ec2012c528ef1..2fc49950463ea 100644 --- a/app/code/Magento/MediaGalleryRenditions/Plugin/SetRenditionPath.php +++ b/app/code/Magento/MediaGalleryRenditions/Plugin/SetRenditionPath.php @@ -91,7 +91,7 @@ public function beforeExecute( $storeId ]; - if (!$this->config->isEnabled()) { + if (!$this->config->isEnabled() || !$this->config->isMediaGalleryEnabled()) { return $arguments; } diff --git a/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php b/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php index 9cf969c16782f..6fcb37398f3ad 100644 --- a/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php +++ b/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php @@ -8,6 +8,7 @@ namespace Magento\MediaGalleryRenditions\Plugin; use Magento\Framework\App\Config\Value; +use Magento\MediaGalleryRenditions\Model\Config; use Magento\MediaGalleryRenditions\Model\Queue\ScheduleRenditionsUpdate; /** @@ -15,6 +16,7 @@ */ 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'; @@ -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; } @@ -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(); } @@ -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(); + } } diff --git a/app/code/Magento/MediaGalleryRenditions/etc/adminhtml/system.xml b/app/code/Magento/MediaGalleryRenditions/etc/adminhtml/system.xml index b60a858da5f26..f36f628cb122f 100644 --- a/app/code/Magento/MediaGalleryRenditions/etc/adminhtml/system.xml +++ b/app/code/Magento/MediaGalleryRenditions/etc/adminhtml/system.xml @@ -10,14 +10,18 @@
+ + + Magento\Config\Model\Config\Source\Yesno + 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. - + validate-zero-or-greater validate-digits Enter the maximum width of an image in pixels. - + validate-zero-or-greater validate-digits Enter the maximum height of an image in pixels. diff --git a/app/code/Magento/MediaGalleryRenditions/etc/config.xml b/app/code/Magento/MediaGalleryRenditions/etc/config.xml index 58c5aa1f11fd2..6b4f2351b8b10 100644 --- a/app/code/Magento/MediaGalleryRenditions/etc/config.xml +++ b/app/code/Magento/MediaGalleryRenditions/etc/config.xml @@ -9,6 +9,7 @@ + 1 1000 1000 diff --git a/app/code/Magento/MediaGalleryUi/Test/Mftf/ActionGroup/AdminMediaGalleryRenditionsEnableActionGroup.xml b/app/code/Magento/MediaGalleryUi/Test/Mftf/ActionGroup/AdminMediaGalleryRenditionsEnableActionGroup.xml new file mode 100644 index 0000000000000..b64247a708242 --- /dev/null +++ b/app/code/Magento/MediaGalleryUi/Test/Mftf/ActionGroup/AdminMediaGalleryRenditionsEnableActionGroup.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/MediaGalleryUi/Test/Mftf/Data/AdobeStockConfigData.xml b/app/code/Magento/MediaGalleryUi/Test/Mftf/Data/AdobeStockConfigData.xml index e8f394a006104..9ac743f2f9983 100644 --- a/app/code/Magento/MediaGalleryUi/Test/Mftf/Data/AdobeStockConfigData.xml +++ b/app/code/Magento/MediaGalleryUi/Test/Mftf/Data/AdobeStockConfigData.xml @@ -15,4 +15,12 @@ system/media_gallery/enabled 0 + + system/media_gallery_renditions/enabled + 1 + + + system/media_gallery_renditions/enabled + 0 + diff --git a/app/code/Magento/MediaGalleryUi/Test/Mftf/Section/AdminConfigSystemSection.xml b/app/code/Magento/MediaGalleryUi/Test/Mftf/Section/AdminConfigSystemSection.xml index b7900f6664c62..f3ab74470e4e4 100644 --- a/app/code/Magento/MediaGalleryUi/Test/Mftf/Section/AdminConfigSystemSection.xml +++ b/app/code/Magento/MediaGalleryUi/Test/Mftf/Section/AdminConfigSystemSection.xml @@ -11,6 +11,8 @@
+ +
diff --git a/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiDisabledSuite.xml b/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiDisabledSuite.xml index 727fbde3f17b6..d5f2abe965575 100644 --- a/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiDisabledSuite.xml +++ b/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiDisabledSuite.xml @@ -9,6 +9,17 @@ + + + + + + + + + + + diff --git a/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiSuite.xml b/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiSuite.xml index 4749fc4a885b0..e81dc807d0f48 100644 --- a/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiSuite.xml +++ b/app/code/Magento/MediaGalleryUi/Test/Mftf/Suite/MediaGalleryUiSuite.xml @@ -15,6 +15,7 @@ +