Skip to content

Commit

Permalink
magento/adobe-stock-integration#1833: Add ability to disable renditio…
Browse files Browse the repository at this point in the history
…ns functionality to stores configuration - added conditions to renditions-related classes
  • Loading branch information
joweecaquicla committed Sep 16, 2020
1 parent 356ef14 commit 27f50e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/code/Magento/MediaGalleryRenditions/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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_RENDITIONS_ENABLED_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 Down Expand Up @@ -54,6 +55,16 @@ public function isEnabled(): bool
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED);
}

/**
* Check if the media gallery renditions is enabled
*
* @return bool
*/
public function isMediaGalleryRenditionsEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLED_PATH);
}

/**
* Get max width
*
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->isMediaGalleryRenditionsEnabled()) {
return $arguments;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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';

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

Expand All @@ -57,6 +59,18 @@ public function afterSave(Value $config, Value $result): Value
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;
|| $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH
|| $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH;
}

/**
* Determine if media gallery renditions is enabled based on configuration value
*
* @param Value $value
* @return bool
*/
private function isMediaGalleryRenditionsEnabled(Value $value): bool
{
return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH && $value->getValue();
}
}

0 comments on commit 27f50e4

Please sign in to comment.