-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Making configurable settings for MAX_IMAGE_WIDTH and MAX_IMAGE_HEIGHT #15942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making configurable settings for MAX_IMAGE_WIDTH and MAX_IMAGE_HEIGHT #15942
Conversation
Hello @eduard13, thank you for your PR. Please, consider fixing the failed static tests |
Hi @rogyar, the failed tests were fixed. |
@eduard13 great job! |
/** | ||
* @var \Magento\Framework\Image\Adapter\ConfigInterface | ||
*/ | ||
protected $imageConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always use private
for new fields.
array $data = [] | ||
) { | ||
$this->_fileSizeService = $fileSize; | ||
$this->imageConfig = $imageConfig; | ||
parent::__construct($context, $data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check https://devdocs.magento.com/guides/v2.0/contributor-guide/backward-compatible-development/#php on how to add new dependency properly, always try to make parent constructor called first.
*/ | ||
public function getImageConfigService() | ||
{ | ||
return $this->imageConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such method must be eliminated as it violates Law of Demeter, inject needed classes into blocks directly and introduce methods like getImageMaxWidth
.
<group id="media_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>Images Upload</label> | ||
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1"> | ||
<label>Max Width</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max -> Maximum
<label>Images Upload</label> | ||
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1"> | ||
<label>Max Width</label> | ||
<validate>validate-zero-or-greater validate-digits</validate> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think zero should be allowed. Validate integer
instead of digits.
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1"> | ||
<label>Max Height</label> | ||
<validate>validate-zero-or-greater validate-digits</validate> | ||
<comment>Max allowed height for uploaded image.</comment> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same three notes as for width should be applied here.
@@ -43,4 +47,24 @@ public function getAdapters() | |||
{ | |||
return $this->config->getValue(self::XML_PATH_IMAGE_ADAPTERS); | |||
} | |||
|
|||
/** | |||
* Get Max Image Width resolution in pixels. For image resizing on client side |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max -> Maximum
} | ||
|
||
/** | ||
* Get Max Image Height resolution in pixels. For image resizing on client side |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max -> Maximum
/** | ||
* Max Image Height resolution in pixels. For image resizing on client side | ||
*/ | ||
const MAX_IMAGE_HEIGHT = 1200; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constants cannot be removed, see http://devdocs.magento.com/guides/v2.0/contributor-guide/backward-compatible-development/. Just deprecate them adding @see
section.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> | ||
<default> | ||
<system> | ||
<media_configuration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be uploader_configuration
, isn't it?
Currently these changes look flawed from modularity perspective. Configuration added to MediaStorage
module but no logic in it, some code added to framework. Please arrange your changes properly.
# Conflicts: # lib/internal/Magento/Framework/File/Uploader.php
Please, resolve conflicts with the mainline branch |
# Conflicts: # app/code/Magento/Backend/Block/Media/Uploader.php
@rogyar the conflicts were fixed. Moreover, I've changed the construct dependency into an optional one. Thank you. |
/** | ||
* @return int | ||
*/ | ||
public function getMaxWidth(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't add new methods to existing interfaces, it would be better to introduce a new interface and implement this methods in Magento/Framework/Image/Adapter/Config.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sidolov a new interface was added and implemented. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thank you! Just a few minor changes are required
@@ -18,7 +18,7 @@ protected function setUp() | |||
{ | |||
$this->configMock = $this->createPartialMock( | |||
\Magento\Framework\Image\Adapter\ConfigInterface::class, | |||
['getAdapterAlias', 'getAdapters'] | |||
['getAdapterAlias', 'getAdapters', 'getMaxWidth', 'getMaxHeight'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove redundant method mocks
* Max Image Height resolution in pixels. For image resizing on client side | ||
* Maximum Image Height resolution in pixels. For image resizing on client side | ||
* @deprecated | ||
* @see ConfigInterface::getMaxHeight() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess UploadConfigInterface
should be here instead of ConfigInterface
Hi @eduard13. Thank you for your contribution. Please, consider to port this solution to 2.3 release line. |
Description
It was added a new system fieldset, where the max-width and max-height can be set.
Stores / Configuration / Advanced / System / Images Configuration
So these 2 values are more flexible now for those which need to have bigger images in their shops.
Fixed Issues (if relevant)
Manual testing scenarios
https://dummyimage.com/3000x700
Contribution checklist