Skip to content

Commit 4175be7

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents 7a776b2 + 6389f4f commit 4175be7

File tree

136 files changed

+3211
-1048
lines changed

Some content is hidden

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

136 files changed

+3211
-1048
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/form/element.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<label for="<?= $element->getHtmlId() ?>"><?= /* @escapeNotVerified */ $element->getLabel() ?>:</label>
6363
<script>
6464
require([
65-
'tinymceDeprecated'
65+
"wysiwygAdapter"
6666
], function(tinyMCE){
6767

6868
tinyMCE.init({

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ protected function _prepareForm()
125125
]
126126
);
127127

128-
$fieldset->addField(
129-
'is_wysiwyg_enabled',
130-
'select',
131-
[
132-
'name' => 'is_wysiwyg_enabled',
133-
'label' => __('Enable WYSIWYG'),
134-
'title' => __('Enable WYSIWYG'),
135-
'values' => $yesnoSource,
136-
]
137-
);
138-
139128
$fieldset->addField(
140129
'is_html_allowed_on_front',
141130
'select',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ public function execute()
4040

4141
// set entered data if was error when we do save
4242
$data = $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getAttributeData(true);
43+
$presentation = $this->_objectManager->get(
44+
\Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation::class
45+
);
4346
if (!empty($data)) {
4447
$model->addData($data);
4548
}
49+
$model->setFrontendInput($presentation->getPresentationInputType($model));
4650
$attributeData = $this->getRequest()->getParam('attribute');
4751
if (!empty($attributeData) && $id === null) {
4852
$model->addData($attributeData);

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1313
use Magento\Catalog\Controller\Adminhtml\Product\Attribute;
1414
use Magento\Catalog\Helper\Product;
15+
use Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation;
1516
use Magento\Catalog\Model\Product\AttributeSet\BuildFactory;
1617
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
1718
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator;
1819
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory;
1920
use Magento\Eav\Model\Entity\Attribute\Set;
2021
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory;
22+
use Magento\Framework\App\ObjectManager;
2123
use Magento\Framework\Cache\FrontendInterface;
2224
use Magento\Framework\Controller\Result\Json;
2325
use Magento\Framework\Controller\ResultFactory;
@@ -67,19 +69,24 @@ class Save extends Attribute
6769
* @var LayoutFactory
6870
*/
6971
private $layoutFactory;
72+
/**
73+
* @var Presentation
74+
*/
75+
private $presentation;
7076

7177
/**
7278
* @param Context $context
7379
* @param FrontendInterface $attributeLabelCache
7480
* @param Registry $coreRegistry
75-
* @param BuildFactory $buildFactory
7681
* @param PageFactory $resultPageFactory
82+
* @param BuildFactory $buildFactory
7783
* @param AttributeFactory $attributeFactory
7884
* @param ValidatorFactory $validatorFactory
7985
* @param CollectionFactory $groupCollectionFactory
8086
* @param FilterManager $filterManager
8187
* @param Product $productHelper
8288
* @param LayoutFactory $layoutFactory
89+
* @param Presentation|null $presentation
8390
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8491
*/
8592
public function __construct(
@@ -93,7 +100,8 @@ public function __construct(
93100
CollectionFactory $groupCollectionFactory,
94101
FilterManager $filterManager,
95102
Product $productHelper,
96-
LayoutFactory $layoutFactory
103+
LayoutFactory $layoutFactory,
104+
Presentation $presentation = null
97105
) {
98106
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
99107
$this->buildFactory = $buildFactory;
@@ -103,6 +111,7 @@ public function __construct(
103111
$this->validatorFactory = $validatorFactory;
104112
$this->groupCollectionFactory = $groupCollectionFactory;
105113
$this->layoutFactory = $layoutFactory;
114+
$this->presentation = $presentation ?: ObjectManager::getInstance()->get(Presentation::class);
106115
}
107116

108117
/**
@@ -191,6 +200,8 @@ public function execute()
191200
}
192201
}
193202

203+
$data = $this->presentation->convertPresentationDataToInputType($data);
204+
194205
if ($attributeId) {
195206
if (!$model->getId()) {
196207
$this->messageManager->addErrorMessage(__('This attribute no longer exists.'));
@@ -205,7 +216,6 @@ public function execute()
205216

206217
$data['attribute_code'] = $model->getAttributeCode();
207218
$data['is_user_defined'] = $model->getIsUserDefined();
208-
$data['frontend_input'] = $model->getFrontendInput();
209219
} else {
210220
/**
211221
* @todo add to helper and specify all relations for properties
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype;
8+
9+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
10+
11+
/**
12+
* Class Input type preprocessor.
13+
*
14+
* @package Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype
15+
*/
16+
class Presentation
17+
{
18+
/**
19+
* Get input type for presentation layer from stored input type.
20+
*
21+
* @param Attribute $attribute
22+
* @return string
23+
*/
24+
public function getPresentationInputType(Attribute $attribute)
25+
{
26+
$inputType = $attribute->getFrontendInput();
27+
if ($inputType == 'textarea' && $attribute->getIsWysiwygEnabled()) {
28+
return 'texteditor';
29+
}
30+
return $inputType;
31+
}
32+
33+
/**
34+
* Convert presentation to storable input type.
35+
*
36+
* @param array $data
37+
*
38+
* @return array
39+
*/
40+
public function convertPresentationDataToInputType(array $data)
41+
{
42+
if ($data['frontend_input'] === 'texteditor') {
43+
$data['is_wysiwyg_enabled'] = 1;
44+
$data['frontend_input'] = 'textarea';
45+
} elseif ($data['frontend_input'] === 'textarea') {
46+
$data['is_wysiwyg_enabled'] = 0;
47+
}
48+
return $data;
49+
}
50+
}

app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
9696
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
9797
* @param \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList
9898
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
99+
* @param DateTimeFormatterInterface $dateTimeFormatter
99100
* @param \Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor
100101
* @param \Magento\Catalog\Model\Indexer\Product\Eav\Processor $indexerEavProcessor
101102
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productFlatIndexerHelper
102103
* @param LockValidatorInterface $lockValidator
103-
* @param DateTimeFormatterInterface $dateTimeFormatter
104104
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
105105
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
106106
* @param array $data

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/EditTest.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class EditTest extends \PHPUnit\Framework\TestCase
6262
*/
6363
protected $session;
6464

65+
/**
66+
* @var \Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation|\PHPUnit_Framework_MockObject_MockObject
67+
*/
68+
protected $presentation;
69+
6570
/**
6671
* @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
6772
*/
@@ -82,11 +87,6 @@ class EditTest extends \PHPUnit\Framework\TestCase
8287
*/
8388
protected $resultPageFactory;
8489

85-
/**
86-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
87-
*/
88-
protected $objectManager;
89-
9090
protected function setUp()
9191
{
9292
$this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)->getMock();
@@ -128,6 +128,11 @@ protected function setUp()
128128
->disableOriginalConstructor()
129129
->getMock();
130130

131+
$this->presentation = $this->getMockBuilder(
132+
\Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation::class
133+
)->disableOriginalConstructor()
134+
->getMock();
135+
131136
$this->blockTemplate = $this->getMockBuilder(\Magento\Backend\Block\Template::class)
132137
->setMethods(['setIsPopup'])
133138
->disableOriginalConstructor()
@@ -142,8 +147,8 @@ protected function setUp()
142147
$this->context->expects($this->any())->method('getResultPageFactory')->willReturn($this->resultPageFactory);
143148
$this->context->expects($this->any())->method('getSession')->willReturn($this->session);
144149

145-
$this->objectManager = new ObjectManager($this);
146-
$this->editController = $this->objectManager->getObject(
150+
$objectManager = new ObjectManager($this);
151+
$this->editController = $objectManager->getObject(
147152
\Magento\Catalog\Controller\Adminhtml\Product\Attribute\Edit::class,
148153
[
149154
'context' => $this->context,
@@ -169,9 +174,10 @@ public function testExecutePopup()
169174
->with(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
170175
->willReturn($this->eavAttribute);
171176
$this->objectManagerMock->expects($this->any())->method('get')
172-
->with(\Magento\Backend\Model\Session::class)
173-
->willReturn($this->session);
174-
177+
->willReturnMap([
178+
[\Magento\Backend\Model\Session::class, $this->session],
179+
[\Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation::class, $this->presentation]
180+
]);
175181
$this->eavAttribute->expects($this->once())->method('setEntityTypeId')->willReturnSelf();
176182
$this->eavAttribute->expects($this->once())->method('addData')->with($attributesData)->willReturnSelf();
177183
$this->eavAttribute->expects($this->any())->method('getName')->willReturn(null);
@@ -219,8 +225,10 @@ public function testExecuteNoPopup()
219225
->with(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
220226
->willReturn($this->eavAttribute);
221227
$this->objectManagerMock->expects($this->any())->method('get')
222-
->with(\Magento\Backend\Model\Session::class)
223-
->willReturn($this->session);
228+
->willReturnMap([
229+
[\Magento\Backend\Model\Session::class, $this->session],
230+
[\Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation::class, $this->presentation]
231+
]);
224232

225233
$this->eavAttribute->expects($this->once())->method('setEntityTypeId')->willReturnSelf();
226234
$this->eavAttribute->expects($this->once())->method('addData')->with($attributesData)->willReturnSelf();

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Source/InputtypeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function testToOptionArray()
3737
$inputTypesSet = [
3838
['value' => 'text', 'label' => 'Text Field'],
3939
['value' => 'textarea', 'label' => 'Text Area'],
40+
['value' => 'texteditor', 'label' => 'Text Editor'],
4041
['value' => 'date', 'label' => 'Date'],
4142
['value' => 'boolean', 'label' => 'Yes/No'],
4243
['value' => 'multiselect', 'label' => 'Multiple Select'],

app/code/Magento/Catalog/Ui/DataProvider/Category/Form/Modifier/WysiwygConfigModifier.php

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

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,4 @@
187187
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
188188
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
189189
</type>
190-
<virtualType name="UiModifierPool" type="Magento\Ui\DataProvider\Modifier\Pool">
191-
<arguments>
192-
<argument name="modifiers" xsi:type="array">
193-
<item name="wysiwyg-category" xsi:type="array">
194-
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Category\Form\Modifier\WysiwygConfigModifier</item>
195-
<item name="sortOrder" xsi:type="number">10</item>
196-
</item>
197-
</argument>
198-
</arguments>
199-
</virtualType>
200-
<type name="Magento\Catalog\Model\Category\DataProvider">
201-
<arguments>
202-
<argument name="pool" xsi:type="object">UiModifierPool</argument>
203-
</arguments>
204-
</type>
205190
</config>

0 commit comments

Comments
 (0)