Skip to content

Commit 992a17f

Browse files
author
Alexander Akimov
authored
Merge pull request #2217 from magento-tsg/2.1.13-develop-pr48
[TSG] Backporting for 2.1 (pr48) (2.1.13)
2 parents df09179 + b61adb8 commit 992a17f

File tree

4 files changed

+16
-25
lines changed
  • app/code/Magento
  • dev/tests/integration/testsuite/Magento/Backend/Model

4 files changed

+16
-25
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ public function getUrl($routePath = null, $routeParams = null)
198198
return $result;
199199
}
200200

201+
$this->getRouteParamsResolver()->unsetData('route_params');
201202
$this->_setRoutePath($routePath);
203+
$extraParams = $this->getRouteParamsResolver()->getRouteParams();
202204
$routeName = $this->_getRouteName('*');
203205
$controllerName = $this->_getControllerName(self::DEFAULT_CONTROLLER_NAME);
204206
$actionName = $this->_getActionName(self::DEFAULT_ACTION_NAME);
@@ -213,6 +215,10 @@ public function getUrl($routePath = null, $routeParams = null)
213215
$routeParams[self::SECRET_KEY_PARAM_NAME] = $secretKey;
214216
}
215217

218+
if (!empty($extraParams)) {
219+
$routeParams = array_merge($extraParams, $routeParams);
220+
}
221+
216222
return parent::getUrl("{$routeName}/{$controllerName}/{$actionName}", $routeParams);
217223
}
218224

app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ class Image extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
5252
*/
5353
private $imageUploader;
5454

55-
/**
56-
* @var string
57-
*/
58-
private $additionalData = '_additional_data_';
59-
6055
/**
6156
* Image constructor.
6257
*
@@ -85,9 +80,9 @@ public function beforeSave($object)
8580
{
8681
$attributeName = $this->getAttribute()->getName();
8782
$value = $object->getData($attributeName);
83+
$imageName = $this->getUploadedImageName($value);
8884

89-
if ($imageName = $this->getUploadedImageName($value)) {
90-
$object->setData($this->additionalData . $attributeName, $value);
85+
if ($imageName) {
9186
$object->setData($attributeName, $imageName);
9287
} else if (!is_string($value)) {
9388
$object->setData($attributeName, '');
@@ -130,27 +125,15 @@ private function getImageUploader()
130125
}
131126

132127
/**
133-
* Check if temporary file is available for new image upload.
134-
*
135-
* @param array $value
136-
* @return bool
137-
*/
138-
private function isTmpFileAvailable($value)
139-
{
140-
return is_array($value) && isset($value[0]['tmp_name']);
141-
}
142-
143-
/**
144-
* Save uploaded file and set its name to category
128+
* Save uploaded file and set its name to category.
145129
*
146130
* @param \Magento\Framework\DataObject $object
147131
* @return \Magento\Catalog\Model\Category\Attribute\Backend\Image
148132
*/
149133
public function afterSave($object)
150134
{
151-
$value = $object->getData($this->additionalData . $this->getAttribute()->getName());
152-
153-
if ($this->isTmpFileAvailable($value) && $imageName = $this->getUploadedImageName($value)) {
135+
$imageName = $object->getData($this->getAttribute()->getName(), null);
136+
if ($imageName) {
154137
try {
155138
$this->getImageUploader()->moveFileFromTmp($imageName);
156139
} catch (\Exception $e) {

app/code/Magento/Catalog/Test/Unit/Model/Category/Attribute/Backend/ImageTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ public function testAfterSave()
164164

165165
$object = new \Magento\Framework\DataObject(
166166
[
167-
'test_attribute' => 'test1234.jpg',
168-
'_additional_data_test_attribute' => [['name' => 'test1234.jpg', 'tmp_name' => 'test-test-1234']]
167+
'test_attribute' => 'test1234.jpg'
169168
]
170169
);
171170
$model->afterSave($object);
@@ -208,7 +207,7 @@ public function testAfterSaveWithExceptions()
208207
->with($this->equalTo($exception));
209208
$object = new \Magento\Framework\DataObject(
210209
[
211-
'_additional_data_test_attribute' => [['name' => 'test1234.jpg', 'tmp_name' => 'test-test-1234']]
210+
'test_attribute' => 'test1234.jpg'
212211
]
213212
);
214213
$model->afterSave($object);

dev/tests/integration/testsuite/Magento/Backend/Model/UrlTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public function testGetUrl()
7575
];
7676
$url = $this->_model->getUrl('path', $routeParams);
7777
$this->assertContains('/param4/' . $paramEncoder->encode('a4==') . '/', $url);
78+
79+
$url = $this->_model->getUrl('route/controller/action/id/100');
80+
$this->assertContains('id/100', $url);
7881
}
7982

8083
/**

0 commit comments

Comments
 (0)