Skip to content

Commit 4037c51

Browse files
authored
Merge pull request #2574 from magento-trigger/team3-delivery
[Team 3] Sprint 8 Delivery - bugfixes
2 parents 70af8a8 + d9f09dd commit 4037c51

File tree

42 files changed

+678
-46
lines changed

Some content is hidden

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

42 files changed

+678
-46
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ public function execute()
139139
->setName($name)
140140
->getAttributeSet();
141141
} catch (AlreadyExistsException $alreadyExists) {
142-
$this->messageManager->addErrorMessage(
143-
__('A "%1" attribute set name already exists. Create a new name and try again.', $name)
144-
);
142+
$this->messageManager->addErrorMessage(__('An attribute set named \'%1\' already exists.', $name));
145143
$this->_session->setAttributeData($data);
146144
return $this->returnResult('catalog/*/edit', ['_current' => true], ['error' => true]);
147145
} catch (LocalizedException $e) {
@@ -202,6 +200,8 @@ public function execute()
202200
}
203201
}
204202

203+
$data = $this->presentation->convertPresentationDataToInputType($data);
204+
205205
if ($attributeId) {
206206
if (!$model->getId()) {
207207
$this->messageManager->addErrorMessage(__('This attribute no longer exists.'));
@@ -216,7 +216,7 @@ public function execute()
216216

217217
$data['attribute_code'] = $model->getAttributeCode();
218218
$data['is_user_defined'] = $model->getIsUserDefined();
219-
$data['frontend_input'] = $model->getFrontendInput();
219+
$data['frontend_input'] = $data['frontend_input'] ?? $model->getFrontendInput();
220220
} else {
221221
/**
222222
* @todo add to helper and specify all relations for properties
@@ -229,8 +229,6 @@ public function execute()
229229
);
230230
}
231231

232-
$data = $this->presentation->convertPresentationDataToInputType($data);
233-
234232
$data += ['is_filterable' => 0, 'is_filterable_in_search' => 0];
235233

236234
if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) {

app/code/Magento/Catalog/Model/Product/Attribute/Frontend/Inputtype/Presentation.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype;
810

911
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
@@ -19,9 +21,9 @@ class Presentation
1921
* Get input type for presentation layer from stored input type.
2022
*
2123
* @param Attribute $attribute
22-
* @return string
24+
* @return string|null
2325
*/
24-
public function getPresentationInputType(Attribute $attribute)
26+
public function getPresentationInputType(Attribute $attribute) :?string
2527
{
2628
$inputType = $attribute->getFrontendInput();
2729
if ($inputType == 'textarea' && $attribute->getIsWysiwygEnabled()) {
@@ -37,12 +39,12 @@ public function getPresentationInputType(Attribute $attribute)
3739
*
3840
* @return array
3941
*/
40-
public function convertPresentationDataToInputType(array $data)
42+
public function convertPresentationDataToInputType(array $data) : array
4143
{
42-
if ($data['frontend_input'] === 'texteditor') {
44+
if (isset($data['frontend_input']) && $data['frontend_input'] === 'texteditor') {
4345
$data['is_wysiwyg_enabled'] = 1;
4446
$data['frontend_input'] = 'textarea';
45-
} elseif ($data['frontend_input'] === 'textarea') {
47+
} elseif (isset($data['frontend_input']) && $data['frontend_input'] === 'textarea') {
4648
$data['is_wysiwyg_enabled'] = 0;
4749
}
4850
return $data;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Frontend\InputType;
9+
10+
class PresentationTest extends \PHPUnit\Framework\TestCase
11+
{
12+
/**
13+
* @var \Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation
14+
*/
15+
private $presentation;
16+
17+
/**
18+
* @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute| \PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $attributeMock;
21+
22+
protected function setUp()
23+
{
24+
$this->presentation = new \Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation();
25+
$this->attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
26+
->disableOriginalConstructor()
27+
->getMock();
28+
}
29+
30+
/**
31+
* @param string $inputType
32+
* @param boolean $isWysiwygEnabled
33+
* @param string $expectedResult
34+
* @dataProvider getPresentationInputTypeDataProvider
35+
*/
36+
public function testGetPresentationInputType(string $inputType, bool $isWysiwygEnabled, string $expectedResult)
37+
{
38+
$this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($inputType);
39+
$this->attributeMock->expects($this->any())->method('getIsWysiwygEnabled')->willReturn($isWysiwygEnabled);
40+
$this->assertEquals($expectedResult, $this->presentation->getPresentationInputType($this->attributeMock));
41+
}
42+
43+
public function getPresentationInputTypeDataProvider()
44+
{
45+
return [
46+
'attribute_is_textarea_and_wysiwyg_enabled' => ['textarea', true, 'texteditor'],
47+
'attribute_is_input_and_wysiwyg_enabled' => ['input', true, 'input'],
48+
'attribute_is_textarea_and_wysiwyg_disabled' => ['textarea', false, 'textarea'],
49+
];
50+
}
51+
52+
/**
53+
* @param array $data
54+
* @param array $expectedResult
55+
* @dataProvider convertPresentationDataToInputTypeDataProvider
56+
*/
57+
public function testConvertPresentationDataToInputType(array $data, array $expectedResult)
58+
{
59+
$this->assertEquals($expectedResult, $this->presentation->convertPresentationDataToInputType($data));
60+
}
61+
62+
public function convertPresentationDataToInputTypeDataProvider()
63+
{
64+
return [
65+
[['key' => 'value'], ['key' => 'value']],
66+
[
67+
['frontend_input' => 'texteditor'],
68+
['frontend_input' => 'textarea', 'is_wysiwyg_enabled' => 1]
69+
],
70+
[
71+
['frontend_input' => 'textarea'],
72+
['frontend_input' => 'textarea', 'is_wysiwyg_enabled' => 0]
73+
],
74+
[
75+
['frontend_input' => 'input'],
76+
['frontend_input' => 'input']
77+
]
78+
];
79+
}
80+
}

app/code/Magento/Cms/Model/Wysiwyg/DefaultConfigProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Cms\Model\Wysiwyg;
810

911
/**
@@ -27,7 +29,7 @@ public function __construct(\Magento\Framework\View\Asset\Repository $assetRepo)
2729
/**
2830
* {@inheritdoc}
2931
*/
30-
public function getConfig($config)
32+
public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Framework\DataObject
3133
{
3234
$config->addData([
3335
'tinymce4' => [

app/code/Magento/Cms/Model/Wysiwyg/Gallery/DefaultConfigProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Cms\Model\Wysiwyg\Gallery;
810

911
class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
@@ -49,7 +51,7 @@ public function __construct(
4951
/**
5052
* {@inheritdoc}
5153
*/
52-
public function getConfig($config)
54+
public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Framework\DataObject
5355
{
5456
$pluginData = (array) $config->getData('plugins');
5557
$imageData = [

app/code/Magento/Cms/Model/WysiwygDefaultConfig.php

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

810
class WysiwygDefaultConfig implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
911
{
1012
/**
1113
* {@inheritdoc}
1214
*/
13-
public function getConfig($config)
15+
public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Framework\DataObject
1416
{
1517
return $config;
1618
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'underscore'
9+
], function ($, _) {
10+
'use strict';
11+
12+
/**
13+
* @constructor
14+
*/
15+
var ConditionsDataNormalizer = function () {
16+
this.patterns = {
17+
validate: /^[a-z0-9_-][a-z0-9_-]*(?:\[(?:\d*|[a-z0-9_-]+)\])*$/i,
18+
key: /[a-z0-9_-]+|(?=\[\])/gi,
19+
push: /^$/,
20+
fixed: /^\d+$/,
21+
named: /^[a-z0-9_-]+$/i
22+
};
23+
};
24+
25+
ConditionsDataNormalizer.prototype = {
26+
/**
27+
* Will convert an object:
28+
* {
29+
* "foo[bar][1][baz]": 123,
30+
* "foo[bar][1][blah]": 321
31+
* "foo[bar][1--1][ah]": 456
32+
* }
33+
*
34+
* to
35+
* {
36+
* "foo": {
37+
* "bar": {
38+
* "1": {
39+
* "baz": 123,
40+
* "blah": 321
41+
* },
42+
* "1--1": {
43+
* "ah": 456
44+
* }
45+
* }
46+
* }
47+
* }
48+
*/
49+
normalize: function normalize(value) {
50+
var el, _this = this;
51+
52+
this.pushes = {};
53+
this.data = {};
54+
55+
_.each(value, function (e, i) {
56+
el = {};
57+
el[i] = e;
58+
59+
_this._addPair({
60+
name: i,
61+
value: e
62+
});
63+
});
64+
65+
return this.data;
66+
},
67+
68+
/**
69+
* @param {Object} base
70+
* @param {String} key
71+
* @param {String} value
72+
* @return {Object}
73+
* @private
74+
*/
75+
_build: function build(base, key, value) {
76+
base[key] = value;
77+
78+
return base;
79+
},
80+
81+
/**
82+
* @param {Object} root
83+
* @param {String} value
84+
* @return {*}
85+
* @private
86+
*/
87+
_makeObject: function makeObject(root, value) {
88+
var keys = root.match(this.patterns.key),
89+
k, idx; // nest, nest, ..., nest
90+
91+
while ((k = keys.pop()) !== undefined) {
92+
// foo[]
93+
if (this.patterns.push.test(k)) {
94+
idx = this._incrementPush(root.replace(/\[\]$/, ''));
95+
value = this._build([], idx, value);
96+
} // foo[n]
97+
else if (this.patterns.fixed.test(k)) {
98+
value = this._build({}, k, value);
99+
} // foo; foo[bar]
100+
else if (this.patterns.named.test(k)) {
101+
value = this._build({}, k, value);
102+
}
103+
}
104+
105+
return value;
106+
},
107+
108+
/**
109+
* @param {String} key
110+
* @return {Number}
111+
* @private
112+
*/
113+
_incrementPush: function incrementPush(key) {
114+
if (this.pushes[key] === undefined) {
115+
this.pushes[key] = 0;
116+
}
117+
118+
return this.pushes[key]++;
119+
},
120+
121+
/**
122+
* @param {Object} pair
123+
* @return {Object}
124+
* @private
125+
*/
126+
_addPair: function addPair(pair) {
127+
var obj = this._makeObject(pair.name, pair.value);
128+
129+
if (!this.patterns.validate.test(pair.name)) {
130+
return this;
131+
}
132+
133+
this.data = $.extend(true, this.data, obj);
134+
135+
return this;
136+
}
137+
};
138+
139+
return ConditionsDataNormalizer;
140+
});

app/code/Magento/Tinymce3/Model/Config/Source/Wysiwyg/Editor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Tinymce3\Model\Config\Source\Wysiwyg;
79

10+
/**
11+
* Class Editor provides configuration value for TinyMCE3 editor
12+
* @deprecated use as configuration value tinymce4 path: mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter
13+
*/
814
class Editor
915
{
1016
/**

app/code/Magento/Tinymce3/Model/Config/Variable/Config.php

Lines changed: 4 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+
7+
declare(strict_types=1);
68
namespace Magento\Tinymce3\Model\Config\Variable;
79

810
/**
911
* Class Config adds variable plugin information required for tinymce3 editor
12+
* @deprecated use \Magento\Variable\Model\Variable\ConfigProvider instead
1013
*/
1114
class Config implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
1215
{
@@ -38,7 +41,7 @@ public function __construct(
3841
* @param \Magento\Framework\DataObject $config
3942
* @return \Magento\Framework\DataObject
4043
*/
41-
public function getConfig($config)
44+
public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Framework\DataObject
4245
{
4346
$settings = $this->defaultVariableConfig->getWysiwygPluginSettings($config);
4447
$pluginConfig = isset($settings['plugins']) ? $settings['plugins'] : [];

0 commit comments

Comments
 (0)