Skip to content

Commit d884094

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-borg/MAGETWO-94172-ElasticSearch-Index-Exception
2 parents dbdb75c + 2de6f90 commit d884094

File tree

82 files changed

+29234
-14506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+29234
-14506
lines changed

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Backend\Block\Media;
79

810
use Magento\Framework\App\ObjectManager;
911
use Magento\Framework\Serialize\Serializer\Json;
12+
use Magento\Framework\Image\Adapter\UploadConfigInterface;
1013

1114
/**
1215
* Adminhtml media library uploader
@@ -35,24 +38,35 @@ class Uploader extends \Magento\Backend\Block\Widget
3538
*/
3639
private $jsonEncoder;
3740

41+
/**
42+
* @var UploadConfigInterface
43+
*/
44+
private $imageConfig;
45+
3846
/**
3947
* @param \Magento\Backend\Block\Template\Context $context
4048
* @param \Magento\Framework\File\Size $fileSize
4149
* @param array $data
4250
* @param Json $jsonEncoder
51+
* @param UploadConfigInterface $imageConfig
4352
*/
4453
public function __construct(
4554
\Magento\Backend\Block\Template\Context $context,
4655
\Magento\Framework\File\Size $fileSize,
4756
array $data = [],
48-
Json $jsonEncoder = null
57+
Json $jsonEncoder = null,
58+
UploadConfigInterface $imageConfig = null
4959
) {
5060
$this->_fileSizeService = $fileSize;
5161
$this->jsonEncoder = $jsonEncoder ?: ObjectManager::getInstance()->get(Json::class);
62+
$this->imageConfig = $imageConfig ?: ObjectManager::getInstance()->get(UploadConfigInterface::class);
63+
5264
parent::__construct($context, $data);
5365
}
5466

5567
/**
68+
* Initialize block.
69+
*
5670
* @return void
5771
*/
5872
protected function _construct()
@@ -90,6 +104,26 @@ public function getFileSizeService()
90104
return $this->_fileSizeService;
91105
}
92106

107+
/**
108+
* Get Image Upload Maximum Width Config.
109+
*
110+
* @return int
111+
*/
112+
public function getImageUploadMaxWidth()
113+
{
114+
return $this->imageConfig->getMaxWidth();
115+
}
116+
117+
/**
118+
* Get Image Upload Maximum Height Config.
119+
*
120+
* @return int
121+
*/
122+
public function getImageUploadMaxHeight()
123+
{
124+
return $this->imageConfig->getMaxHeight();
125+
}
126+
93127
/**
94128
* Prepares layout and set element renderer
95129
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@
336336
</depends>
337337
</field>
338338
</group>
339+
<group id="upload_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
340+
<label>Images Upload Configuration</label>
341+
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
342+
<label>Maximum Width</label>
343+
<validate>validate-greater-than-zero validate-number required-entry</validate>
344+
<comment>Maximum allowed width for uploaded image.</comment>
345+
</field>
346+
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
347+
<label>Maximum Height</label>
348+
<validate>validate-greater-than-zero validate-number required-entry</validate>
349+
<comment>Maximum allowed height for uploaded image.</comment>
350+
</field>
351+
</group>
339352
</section>
340353
<section id="admin" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
341354
<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 */ \Magento\Framework\File\Uploader::MAX_IMAGE_WIDTH ?> ,
17-
"maxHeight": <?= /* @escapeNotVerified */ \Magento\Framework\File\Uploader::MAX_IMAGE_HEIGHT ?>
16+
"maxWidth":<?= /* @escapeNotVerified */ $block->getImageUploadMaxWidth() ?> ,
17+
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageUploadMaxHeight() ?>
1818
}
1919
}'
2020
>

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery.php

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
*/
1212
namespace Magento\Catalog\Block\Adminhtml\Product\Helper\Form;
1313

14+
use Magento\Framework\App\ObjectManager;
15+
use Magento\Framework\App\Request\DataPersistorInterface;
1416
use Magento\Framework\Registry;
1517
use Magento\Catalog\Model\Product;
1618
use Magento\Eav\Model\Entity\Attribute;
1719
use Magento\Catalog\Api\Data\ProductInterface;
1820

21+
/**
22+
* Adminhtml gallery block
23+
*/
1924
class Gallery extends \Magento\Framework\View\Element\AbstractBlock
2025
{
2126
/**
@@ -66,27 +71,37 @@ class Gallery extends \Magento\Framework\View\Element\AbstractBlock
6671
*/
6772
protected $registry;
6873

74+
/**
75+
* @var DataPersistorInterface
76+
*/
77+
private $dataPersistor;
78+
6979
/**
7080
* @param \Magento\Framework\View\Element\Context $context
7181
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
7282
* @param Registry $registry
7383
* @param \Magento\Framework\Data\Form $form
7484
* @param array $data
85+
* @param DataPersistorInterface|null $dataPersistor
7586
*/
7687
public function __construct(
7788
\Magento\Framework\View\Element\Context $context,
7889
\Magento\Store\Model\StoreManagerInterface $storeManager,
7990
Registry $registry,
8091
\Magento\Framework\Data\Form $form,
81-
$data = []
92+
$data = [],
93+
DataPersistorInterface $dataPersistor = null
8294
) {
8395
$this->storeManager = $storeManager;
8496
$this->registry = $registry;
8597
$this->form = $form;
98+
$this->dataPersistor = $dataPersistor ?: ObjectManager::getInstance()->get(DataPersistorInterface::class);
8699
parent::__construct($context, $data);
87100
}
88101

89102
/**
103+
* Returns element html.
104+
*
90105
* @return string
91106
*/
92107
public function getElementHtml()
@@ -102,7 +117,24 @@ public function getElementHtml()
102117
*/
103118
public function getImages()
104119
{
105-
return $this->getDataObject()->getData('media_gallery') ?: null;
120+
$images = $this->getDataObject()->getData('media_gallery') ?: null;
121+
if ($images === null) {
122+
$images = ((array)$this->dataPersistor->get('catalog_product'))['product']['media_gallery'] ?? null;
123+
}
124+
125+
return $images;
126+
}
127+
128+
/**
129+
* Get value for given type.
130+
*
131+
* @param string $type
132+
* @return string|null
133+
*/
134+
public function getImageValue(string $type)
135+
{
136+
$product = (array)$this->dataPersistor->get('catalog_product');
137+
return $product['product'][$type] ?? null;
106138
}
107139

108140
/**
@@ -122,6 +154,8 @@ public function getContentHtml()
122154
}
123155

124156
/**
157+
* Returns html id
158+
*
125159
* @return string
126160
*/
127161
protected function getHtmlId()
@@ -130,6 +164,8 @@ protected function getHtmlId()
130164
}
131165

132166
/**
167+
* Returns name
168+
*
133169
* @return string
134170
*/
135171
public function getName()
@@ -138,6 +174,8 @@ public function getName()
138174
}
139175

140176
/**
177+
* Returns suffix for field name
178+
*
141179
* @return string
142180
*/
143181
public function getFieldNameSuffix()
@@ -146,6 +184,8 @@ public function getFieldNameSuffix()
146184
}
147185

148186
/**
187+
* Returns data scope html id
188+
*
149189
* @return string
150190
*/
151191
public function getDataScopeHtmlId()
@@ -230,7 +270,6 @@ public function getDataObject()
230270
/**
231271
* Retrieve attribute field name
232272
*
233-
*
234273
* @param Attribute $attribute
235274
* @return string
236275
*/
@@ -244,6 +283,8 @@ public function getAttributeFieldName($attribute)
244283
}
245284

246285
/**
286+
* Returns html content of the block
287+
*
247288
* @return string
248289
*/
249290
public function toHtml()

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Magento\Framework\App\Filesystem\DirectoryList;
1919
use Magento\Framework\Exception\FileSystemException;
2020

21+
/**
22+
* Block for gallery content.
23+
*/
2124
class Content extends \Magento\Backend\Block\Widget
2225
{
2326
/**
@@ -58,6 +61,8 @@ public function __construct(
5861
}
5962

6063
/**
64+
* Prepare layout.
65+
*
6166
* @return AbstractBlock
6267
*/
6368
protected function _prepareLayout()
@@ -103,6 +108,8 @@ public function getUploaderHtml()
103108
}
104109

105110
/**
111+
* Returns js object name
112+
*
106113
* @return string
107114
*/
108115
public function getJsObjectName()
@@ -111,6 +118,8 @@ public function getJsObjectName()
111118
}
112119

113120
/**
121+
* Returns buttons for add image action.
122+
*
114123
* @return string
115124
*/
116125
public function getAddImagesButton()
@@ -124,6 +133,8 @@ public function getAddImagesButton()
124133
}
125134

126135
/**
136+
* Returns image json
137+
*
127138
* @return string
128139
*/
129140
public function getImagesJson()
@@ -169,6 +180,8 @@ private function sortImagesByPosition($images)
169180
}
170181

171182
/**
183+
* Returns image values json
184+
*
172185
* @return string
173186
*/
174187
public function getImagesValuesJson()
@@ -193,9 +206,11 @@ public function getImageTypes()
193206
$imageTypes = [];
194207
foreach ($this->getMediaAttributes() as $attribute) {
195208
/* @var $attribute \Magento\Eav\Model\Entity\Attribute */
209+
$value = $this->getElement()->getDataObject()->getData($attribute->getAttributeCode())
210+
?: $this->getElement()->getImageValue($attribute->getAttributeCode());
196211
$imageTypes[$attribute->getAttributeCode()] = [
197212
'code' => $attribute->getAttributeCode(),
198-
'value' => $this->getElement()->getDataObject()->getData($attribute->getAttributeCode()),
213+
'value' => $value,
199214
'label' => $attribute->getFrontend()->getLabel(),
200215
'scope' => __($this->getElement()->getScopeLabel($attribute)),
201216
'name' => $this->getElement()->getAttributeFieldName($attribute),
@@ -241,6 +256,8 @@ public function getImageTypesJson()
241256
}
242257

243258
/**
259+
* Returns image helper object.
260+
*
244261
* @return \Magento\Catalog\Helper\Image
245262
* @deprecated 101.0.3
246263
*/

0 commit comments

Comments
 (0)