Skip to content

Commit

Permalink
Refactoring the new added system values. Adding validation for system…
Browse files Browse the repository at this point in the history
… values. Introducing the new methods in block, and removed the injecting image service.
  • Loading branch information
eduard13 committed Jun 22, 2018
1 parent e1591e4 commit 0c8221b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 48 deletions.
31 changes: 22 additions & 9 deletions app/code/Magento/Backend/Block/Media/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Magento\Backend\Block\Media;

use Magento\Framework\Image\Adapter\ConfigInterface;

/**
* Adminhtml media library uploader
* @api
Expand All @@ -30,25 +32,26 @@ class Uploader extends \Magento\Backend\Block\Widget
protected $_fileSizeService;

/**
* @var \Magento\Framework\Image\Adapter\ConfigInterface
* @var ConfigInterface
*/
protected $imageConfig;
private $imageConfig;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\File\Size $fileSize
* @param \Magento\Framework\Image\Adapter\ConfigInterface $imageConfig
* @param ConfigInterface $imageConfig
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\File\Size $fileSize,
\Magento\Framework\Image\Adapter\ConfigInterface $imageConfig,
ConfigInterface $imageConfig,
array $data = []
) {
parent::__construct($context, $data);

$this->_fileSizeService = $fileSize;
$this->imageConfig = $imageConfig;
parent::__construct($context, $data);
}

/**
Expand Down Expand Up @@ -90,13 +93,23 @@ public function getFileSizeService()
}

/**
* Get image config
* Get Image Upload Maximum Width Config
*
* @return int
*/
public function getUploadImageMaxWidth()
{
return $this->imageConfig->getMaxWidth();
}

/**
* Get Image Upload Maximum Height Config
*
* @return \Magento\Framework\Image\Adapter\ConfigInterface
* @return int
*/
public function getImageConfigService()
public function getUploadImageMaxHeight()
{
return $this->imageConfig;
return $this->imageConfig->getMaxHeight();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions app/code/Magento/Backend/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,19 @@
</depends>
</field>
</group>
<group id="upload_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Images Upload Configuration</label>
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Maximum Width</label>
<validate>validate-greater-than-zero validate-number required-entry</validate>
<comment>Maximum allowed width for uploaded image.</comment>
</field>
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Maximum Height</label>
<validate>validate-greater-than-zero validate-number required-entry</validate>
<comment>Maximum allowed height for uploaded image.</comment>
</field>
</group>
</section>
<section id="admin" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Admin</label>
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Backend/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<dashboard>
<enable_charts>1</enable_charts>
</dashboard>
<upload_configuration>
<max_width>1920</max_width>
<max_height>1200</max_height>
</upload_configuration>
</system>
<general>
<validator_data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
data-mage-init='{
"Magento_Backend/js/media-uploader" : {
"maxFileSize": <?= /* @escapeNotVerified */ $block->getFileSizeService()->getMaxFileSize() ?>,
"maxWidth":<?= /* @escapeNotVerified */ $block->getImageConfigService()->getMaxWidth() ?> ,
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageConfigService()->getMaxHeight() ?>
"maxWidth":<?= /* @escapeNotVerified */ $block->getUploadImageMaxWidth() ?> ,
"maxHeight": <?= /* @escapeNotVerified */ $block->getUploadImageMaxHeight() ?>
}
}'
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ require([
maxFileSize: <?= (int) $block->getFileSizeService()->getMaxFileSize() ?> * 10
}, {
action: 'resize',
maxWidth: <?= (float) $block->getImageConfigService()->getMaxWidth() ?> ,
maxHeight: <?= (float) $block->getImageConfigService()->getMaxHeight() ?>
maxWidth: <?= $block->getUploadImageMaxWidth() ?> ,
maxHeight: <?= $block->getUploadImageMaxHeight() ?>
}, {
action: 'save'
}]
Expand Down
13 changes: 0 additions & 13 deletions app/code/Magento/MediaStorage/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@
<label>Environment Update Time</label>
</field>
</group>
<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>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Max allowed width for uploaded image.</comment>
</field>
<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>
</field>
</group>
</section>
</system>
</config>
17 changes: 0 additions & 17 deletions app/code/Magento/MediaStorage/etc/config.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
array $data = []
) {
$this->_storageHelper = $storageHelper;
$this->imageConfig = $imageConfig;

parent::__construct($context, $fileSize, $imageConfig, $data);
}

Expand Down
15 changes: 15 additions & 0 deletions lib/internal/Magento/Framework/File/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Framework\File;

use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\Image\Adapter\ConfigInterface;

/**
* File upload class
Expand Down Expand Up @@ -132,6 +133,20 @@ class Uploader
*/
const TMP_NAME_EMPTY = 666;

/**
* Maximum Image Width resolution in pixels. For image resizing on client side
* @deprecated
* @see ConfigInterface::getMaxWidth()
*/
const MAX_IMAGE_WIDTH = 1920;

/**
* Maximum Image Height resolution in pixels. For image resizing on client side
* @deprecated
* @see ConfigInterface::getMaxHeight()
*/
const MAX_IMAGE_HEIGHT = 1200;

/**
* Resulting of uploaded file
*
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/Magento/Framework/Image/Adapter/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Config implements \Magento\Framework\Image\Adapter\ConfigInterface

const XML_PATH_IMAGE_ADAPTERS = 'dev/image/adapters';

const XML_PATH_MAX_WIDTH_IMAGE = 'system/media_configuration/max_width';
const XML_PATH_MAX_WIDTH_IMAGE = 'system/upload_configuration/max_width';

const XML_PATH_MAX_HEIGHT_IMAGE = 'system/media_configuration/max_height';
const XML_PATH_MAX_HEIGHT_IMAGE = 'system/upload_configuration/max_height';

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
Expand Down Expand Up @@ -49,7 +49,7 @@ public function getAdapters()
}

/**
* Get Max Image Width resolution in pixels. For image resizing on client side
* Get Maximum Image Width resolution in pixels. For image resizing on client side
*
* @return int
*/
Expand All @@ -59,7 +59,7 @@ public function getMaxWidth()
}

/**
* Get Max Image Height resolution in pixels. For image resizing on client side
* Get Maximum Image Height resolution in pixels. For image resizing on client side
*
* @return int
*/
Expand Down

0 comments on commit 0c8221b

Please sign in to comment.