Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 0c8221b

Browse files
committed
Refactoring the new added system values. Adding validation for system values. Introducing the new methods in block, and removed the injecting image service.
1 parent e1591e4 commit 0c8221b

File tree

10 files changed

+63
-48
lines changed

10 files changed

+63
-48
lines changed

app/code/Magento/Backend/Block/Media/Uploader.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Backend\Block\Media;
99

10+
use Magento\Framework\Image\Adapter\ConfigInterface;
11+
1012
/**
1113
* Adminhtml media library uploader
1214
* @api
@@ -30,25 +32,26 @@ class Uploader extends \Magento\Backend\Block\Widget
3032
protected $_fileSizeService;
3133

3234
/**
33-
* @var \Magento\Framework\Image\Adapter\ConfigInterface
35+
* @var ConfigInterface
3436
*/
35-
protected $imageConfig;
37+
private $imageConfig;
3638

3739
/**
3840
* @param \Magento\Backend\Block\Template\Context $context
3941
* @param \Magento\Framework\File\Size $fileSize
40-
* @param \Magento\Framework\Image\Adapter\ConfigInterface $imageConfig
42+
* @param ConfigInterface $imageConfig
4143
* @param array $data
4244
*/
4345
public function __construct(
4446
\Magento\Backend\Block\Template\Context $context,
4547
\Magento\Framework\File\Size $fileSize,
46-
\Magento\Framework\Image\Adapter\ConfigInterface $imageConfig,
48+
ConfigInterface $imageConfig,
4749
array $data = []
4850
) {
51+
parent::__construct($context, $data);
52+
4953
$this->_fileSizeService = $fileSize;
5054
$this->imageConfig = $imageConfig;
51-
parent::__construct($context, $data);
5255
}
5356

5457
/**
@@ -90,13 +93,23 @@ public function getFileSizeService()
9093
}
9194

9295
/**
93-
* Get image config
96+
* Get Image Upload Maximum Width Config
97+
*
98+
* @return int
99+
*/
100+
public function getUploadImageMaxWidth()
101+
{
102+
return $this->imageConfig->getMaxWidth();
103+
}
104+
105+
/**
106+
* Get Image Upload Maximum Height Config
94107
*
95-
* @return \Magento\Framework\Image\Adapter\ConfigInterface
108+
* @return int
96109
*/
97-
public function getImageConfigService()
110+
public function getUploadImageMaxHeight()
98111
{
99-
return $this->imageConfig;
112+
return $this->imageConfig->getMaxHeight();
100113
}
101114

102115
/**

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@
319319
</depends>
320320
</field>
321321
</group>
322+
<group id="upload_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
323+
<label>Images Upload Configuration</label>
324+
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
325+
<label>Maximum Width</label>
326+
<validate>validate-greater-than-zero validate-number required-entry</validate>
327+
<comment>Maximum allowed width for uploaded image.</comment>
328+
</field>
329+
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
330+
<label>Maximum Height</label>
331+
<validate>validate-greater-than-zero validate-number required-entry</validate>
332+
<comment>Maximum allowed height for uploaded image.</comment>
333+
</field>
334+
</group>
322335
</section>
323336
<section id="admin" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
324337
<label>Admin</label>

app/code/Magento/Backend/etc/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<dashboard>
2929
<enable_charts>1</enable_charts>
3030
</dashboard>
31+
<upload_configuration>
32+
<max_width>1920</max_width>
33+
<max_height>1200</max_height>
34+
</upload_configuration>
3135
</system>
3236
<general>
3337
<validator_data>

app/code/Magento/Backend/view/adminhtml/templates/media/uploader.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
data-mage-init='{
1414
"Magento_Backend/js/media-uploader" : {
1515
"maxFileSize": <?= /* @escapeNotVerified */ $block->getFileSizeService()->getMaxFileSize() ?>,
16-
"maxWidth":<?= /* @escapeNotVerified */ $block->getImageConfigService()->getMaxWidth() ?> ,
17-
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageConfigService()->getMaxHeight() ?>
16+
"maxWidth":<?= /* @escapeNotVerified */ $block->getUploadImageMaxWidth() ?> ,
17+
"maxHeight": <?= /* @escapeNotVerified */ $block->getUploadImageMaxHeight() ?>
1818
}
1919
}'
2020
>

app/code/Magento/Cms/view/adminhtml/templates/browser/content/uploader.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ require([
101101
maxFileSize: <?= (int) $block->getFileSizeService()->getMaxFileSize() ?> * 10
102102
}, {
103103
action: 'resize',
104-
maxWidth: <?= (float) $block->getImageConfigService()->getMaxWidth() ?> ,
105-
maxHeight: <?= (float) $block->getImageConfigService()->getMaxHeight() ?>
104+
maxWidth: <?= $block->getUploadImageMaxWidth() ?> ,
105+
maxHeight: <?= $block->getUploadImageMaxHeight() ?>
106106
}, {
107107
action: 'save'
108108
}]

app/code/Magento/MediaStorage/etc/adminhtml/system.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@
3030
<label>Environment Update Time</label>
3131
</field>
3232
</group>
33-
<group id="media_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
34-
<label>Images Upload</label>
35-
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
36-
<label>Max Width</label>
37-
<validate>validate-zero-or-greater validate-digits</validate>
38-
<comment>Max allowed width for uploaded image.</comment>
39-
</field>
40-
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
41-
<label>Max Height</label>
42-
<validate>validate-zero-or-greater validate-digits</validate>
43-
<comment>Max allowed height for uploaded image.</comment>
44-
</field>
45-
</group>
4633
</section>
4734
</system>
4835
</config>

app/code/Magento/MediaStorage/etc/config.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Uploader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
array $data = []
4444
) {
4545
$this->_storageHelper = $storageHelper;
46-
$this->imageConfig = $imageConfig;
46+
4747
parent::__construct($context, $fileSize, $imageConfig, $data);
4848
}
4949

lib/internal/Magento/Framework/File/Uploader.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Framework\File;
77

88
use Magento\Framework\Filesystem\DriverInterface;
9+
use Magento\Framework\Image\Adapter\ConfigInterface;
910

1011
/**
1112
* File upload class
@@ -132,6 +133,20 @@ class Uploader
132133
*/
133134
const TMP_NAME_EMPTY = 666;
134135

136+
/**
137+
* Maximum Image Width resolution in pixels. For image resizing on client side
138+
* @deprecated
139+
* @see ConfigInterface::getMaxWidth()
140+
*/
141+
const MAX_IMAGE_WIDTH = 1920;
142+
143+
/**
144+
* Maximum Image Height resolution in pixels. For image resizing on client side
145+
* @deprecated
146+
* @see ConfigInterface::getMaxHeight()
147+
*/
148+
const MAX_IMAGE_HEIGHT = 1200;
149+
135150
/**
136151
* Resulting of uploaded file
137152
*

lib/internal/Magento/Framework/Image/Adapter/Config.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class Config implements \Magento\Framework\Image\Adapter\ConfigInterface
1111

1212
const XML_PATH_IMAGE_ADAPTERS = 'dev/image/adapters';
1313

14-
const XML_PATH_MAX_WIDTH_IMAGE = 'system/media_configuration/max_width';
14+
const XML_PATH_MAX_WIDTH_IMAGE = 'system/upload_configuration/max_width';
1515

16-
const XML_PATH_MAX_HEIGHT_IMAGE = 'system/media_configuration/max_height';
16+
const XML_PATH_MAX_HEIGHT_IMAGE = 'system/upload_configuration/max_height';
1717

1818
/**
1919
* @var \Magento\Framework\App\Config\ScopeConfigInterface
@@ -49,7 +49,7 @@ public function getAdapters()
4949
}
5050

5151
/**
52-
* Get Max Image Width resolution in pixels. For image resizing on client side
52+
* Get Maximum Image Width resolution in pixels. For image resizing on client side
5353
*
5454
* @return int
5555
*/
@@ -59,7 +59,7 @@ public function getMaxWidth()
5959
}
6060

6161
/**
62-
* Get Max Image Height resolution in pixels. For image resizing on client side
62+
* Get Maximum Image Height resolution in pixels. For image resizing on client side
6363
*
6464
* @return int
6565
*/

0 commit comments

Comments
 (0)