Skip to content

Commit ce047bd

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents e147c68 + b71c1f2 commit ce047bd

File tree

25 files changed

+298
-89
lines changed

25 files changed

+298
-89
lines changed

app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ interface ProductAttributeInterface extends \Magento\Catalog\Api\Data\EavAttribu
3232
const CODE_TIER_PRICE_FIELD_VALUE_TYPE = 'value_type';
3333
const CODE_SEO_FIELD_META_DESCRIPTION = 'meta_description';
3434
const CODE_WEIGHT = 'weight';
35+
36+
/**
37+
* @return \Magento\Eav\Api\Data\AttributeExtensionInterface|null
38+
*/
39+
public function getExtensionAttributes();
3540
}

app/code/Magento/Catalog/Model/Product/Attribute/Source/Inputtype.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ class Inputtype extends \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputt
2828
/**
2929
* @param \Magento\Framework\Event\ManagerInterface $eventManager
3030
* @param \Magento\Framework\Registry $coreRegistry
31+
* @param array $optionsArray
3132
*/
3233
public function __construct(
3334
\Magento\Framework\Event\ManagerInterface $eventManager,
34-
\Magento\Framework\Registry $coreRegistry
35+
\Magento\Framework\Registry $coreRegistry,
36+
array $optionsArray = []
3537
) {
3638
$this->_eventManager = $eventManager;
3739
$this->_coreRegistry = $coreRegistry;
40+
parent::__construct($optionsArray);
3841
}
3942

4043
/**

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* @method int setSearchWeight(int $value)
2222
* @method bool getIsUsedForPriceRules()
2323
* @method int setIsUsedForPriceRules(int $value)
24-
* @method \Magento\Eav\Api\Data\AttributeExtensionInterface getExtensionAttributes()
2524
*
2625
* @author Magento Core Team <[email protected]>
2726
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -80,6 +79,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
8079
*/
8180
protected $_indexerEavProcessor;
8281

82+
/**
83+
* @var \Magento\Eav\Api\Data\AttributeExtensionFactory
84+
*/
85+
private $eavAttributeFactory;
86+
8387
/**
8488
* @param \Magento\Framework\Model\Context $context
8589
* @param \Magento\Framework\Registry $registry
@@ -101,9 +105,10 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
101105
* @param \Magento\Catalog\Model\Indexer\Product\Eav\Processor $indexerEavProcessor
102106
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productFlatIndexerHelper
103107
* @param LockValidatorInterface $lockValidator
104-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
105-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
108+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
109+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
106110
* @param array $data
111+
* @param \Magento\Eav\Api\Data\AttributeExtensionFactory|null $eavAttributeFactory
107112
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
108113
*/
109114
public function __construct(
@@ -129,12 +134,15 @@ public function __construct(
129134
LockValidatorInterface $lockValidator,
130135
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
131136
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
132-
array $data = []
137+
array $data = [],
138+
\Magento\Eav\Api\Data\AttributeExtensionFactory $eavAttributeFactory = null
133139
) {
134140
$this->_indexerEavProcessor = $indexerEavProcessor;
135141
$this->_productFlatIndexerProcessor = $productFlatIndexerProcessor;
136142
$this->_productFlatIndexerHelper = $productFlatIndexerHelper;
137143
$this->attrLockValidator = $lockValidator;
144+
$this->eavAttributeFactory = $eavAttributeFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
145+
->get(\Magento\Eav\Api\Data\AttributeExtensionFactory::class);
138146
parent::__construct(
139147
$context,
140148
$registry,
@@ -887,4 +895,18 @@ public function setIsFilterableInGrid($isFilterableInGrid)
887895
$this->setData(self::IS_FILTERABLE_IN_GRID, $isFilterableInGrid);
888896
return $this;
889897
}
898+
899+
/**
900+
* @return \Magento\Eav\Api\Data\AttributeExtensionInterface
901+
*/
902+
public function getExtensionAttributes()
903+
{
904+
$extensionAttributes = $this->_getExtensionAttributes();
905+
if (null === $extensionAttributes) {
906+
/** @var \Magento\Eav\Api\Data\AttributeExtensionInterface $extensionAttributes */
907+
$extensionAttributes = $this->eavAttributeFactory->create();
908+
$this->setExtensionAttributes($extensionAttributes);
909+
}
910+
return $extensionAttributes;
911+
}
890912
}

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,37 @@ protected function setUp()
2727
$this->inputtypeModel = $this->objectManagerHelper->getObject(
2828
\Magento\Catalog\Model\Product\Attribute\Source\Inputtype::class,
2929
[
30-
'coreRegistry' => $this->registry
30+
'coreRegistry' => $this->registry,
31+
'optionsArray' => $this->getInputTypeSet()
3132
]
3233
);
3334
}
3435

3536
public function testToOptionArray()
3637
{
37-
$inputTypesSet = [
38+
39+
$extraValues = [
40+
['value' => 'price', 'label' => 'Price'],
41+
['value' => 'media_image', 'label' => 'Media Image']
42+
];
43+
$inputTypesSet = $this->getInputTypeSet();
44+
$inputTypesSet = array_merge($inputTypesSet, $extraValues);
45+
46+
$this->registry->expects($this->once())->method('registry');
47+
$this->registry->expects($this->once())->method('register');
48+
$this->assertEquals($inputTypesSet, $this->inputtypeModel->toOptionArray());
49+
}
50+
51+
private function getInputTypeSet()
52+
{
53+
return [
3854
['value' => 'text', 'label' => 'Text Field'],
3955
['value' => 'textarea', 'label' => 'Text Area'],
4056
['value' => 'texteditor', 'label' => 'Text Editor'],
4157
['value' => 'date', 'label' => 'Date'],
4258
['value' => 'boolean', 'label' => 'Yes/No'],
4359
['value' => 'multiselect', 'label' => 'Multiple Select'],
44-
['value' => 'select', 'label' => 'Dropdown'],
45-
['value' => 'price', 'label' => 'Price'],
46-
['value' => 'media_image', 'label' => 'Media Image'],
60+
['value' => 'select', 'label' => 'Dropdown']
4761
];
48-
49-
$this->registry->expects($this->once())->method('registry');
50-
$this->registry->expects($this->once())->method('register');
51-
$this->assertEquals($inputTypesSet, $this->inputtypeModel->toOptionArray());
5262
}
5363
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Magento\Ui\Component\Form\Fieldset;
3232
use Magento\Ui\DataProvider\Mapper\FormElement as FormElementMapper;
3333
use Magento\Ui\DataProvider\Mapper\MetaProperties as MetaPropertiesMapper;
34+
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav\CompositeConfigProcessor;
3435

3536
/**
3637
* Class Eav
@@ -187,6 +188,11 @@ class Eav extends AbstractModifier
187188
*/
188189
private $localeCurrency;
189190

191+
/**
192+
* @var CompositeConfigProcessor
193+
*/
194+
private $wysiwygConfigProcessor;
195+
190196
/**
191197
* @param LocatorInterface $locator
192198
* @param CatalogEavValidationRules $catalogEavValidationRules
@@ -207,6 +213,7 @@ class Eav extends AbstractModifier
207213
* @param DataPersistorInterface $dataPersistor
208214
* @param array $attributesToDisable
209215
* @param array $attributesToEliminate
216+
* @param CompositeConfigProcessor|null $wysiwygConfigProcessor
210217
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
211218
*/
212219
public function __construct(
@@ -228,7 +235,8 @@ public function __construct(
228235
ScopeOverriddenValue $scopeOverriddenValue,
229236
DataPersistorInterface $dataPersistor,
230237
$attributesToDisable = [],
231-
$attributesToEliminate = []
238+
$attributesToEliminate = [],
239+
CompositeConfigProcessor $wysiwygConfigProcessor = null
232240
) {
233241
$this->locator = $locator;
234242
$this->catalogEavValidationRules = $catalogEavValidationRules;
@@ -249,6 +257,8 @@ public function __construct(
249257
$this->dataPersistor = $dataPersistor;
250258
$this->attributesToDisable = $attributesToDisable;
251259
$this->attributesToEliminate = $attributesToEliminate;
260+
$this->wysiwygConfigProcessor = $wysiwygConfigProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
261+
->get(CompositeConfigProcessor::class);
252262
}
253263

254264
/**
@@ -779,13 +789,7 @@ private function customizeWysiwyg(ProductAttributeInterface $attribute, array $m
779789

780790
$meta['arguments']['data']['config']['formElement'] = WysiwygElement::NAME;
781791
$meta['arguments']['data']['config']['wysiwyg'] = true;
782-
$meta['arguments']['data']['config']['wysiwygConfigData'] = [
783-
'add_variables' => false,
784-
'add_widgets' => false,
785-
'add_directives' => true,
786-
'use_container' => true,
787-
'container_class' => 'hor-scroll',
788-
];
792+
$meta['arguments']['data']['config']['wysiwygConfigData'] = $this->wysiwygConfigProcessor->process($attribute);
789793

790794
return $meta;
791795
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav;
10+
11+
use Psr\Log\LoggerInterface as Logger;
12+
13+
class CompositeConfigProcessor implements WysiwygConfigDataProcessorInterface
14+
{
15+
/**
16+
* @var Logger
17+
*/
18+
private $logger;
19+
20+
/**
21+
* @var array
22+
*/
23+
private $eavWysiwygDataProcessors = [];
24+
25+
/**
26+
* CompositeConfigProcessor constructor.
27+
* @param array $eavWysiwygDataProcessors
28+
*/
29+
public function __construct(Logger $logger, array $eavWysiwygDataProcessors)
30+
{
31+
$this->logger = $logger;
32+
$this->eavWysiwygDataProcessors = $eavWysiwygDataProcessors;
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function process(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute)
39+
{
40+
$wysiwygConfigData = [];
41+
42+
foreach ($this->eavWysiwygDataProcessors as $processor) {
43+
if (!$processor instanceof WysiwygConfigDataProcessorInterface) {
44+
$this->logger->critical(
45+
__(
46+
'Processor %1 doesn\'t implement WysiwygConfigDataProcessorInterface. It will be skipped',
47+
get_class($processor)
48+
)
49+
);
50+
continue;
51+
}
52+
53+
$wysiwygConfigData = array_merge_recursive($wysiwygConfigData, $processor->process($attribute));
54+
}
55+
56+
return $wysiwygConfigData;
57+
}
58+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav;
10+
11+
/**
12+
* Add data to related to $meta['arguments']['data']['config']['wysiwygConfigData']
13+
*/
14+
class WysiwygConfigDataProcessor implements WysiwygConfigDataProcessorInterface
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function process(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute)
20+
{
21+
return [
22+
'add_variables' => false,
23+
'add_widgets' => false,
24+
'add_directives' => true,
25+
'use_container' => true,
26+
'container_class' => 'hor-scroll',
27+
];
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav;
10+
11+
/**
12+
* Interface WysiwygConfigDataProcessorInterface
13+
*/
14+
interface WysiwygConfigDataProcessorInterface
15+
{
16+
/**
17+
* Returns wysiwygConfigData array to render wysiwyg ui component
18+
*
19+
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
20+
* @return array
21+
*/
22+
public function process(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute);
23+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,11 @@
193193
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
194194
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
195195
</type>
196+
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav\CompositeConfigProcessor">
197+
<arguments>
198+
<argument name="eavWysiwygDataProcessors" xsi:type="array">
199+
<item name="default" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav\WysiwygConfigDataProcessor</item>
200+
</argument>
201+
</arguments>
202+
</type>
196203
</config>

app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
</imageUploader>
180180
</formElements>
181181
</field>
182-
<field name="description" template="Magento_Catalog/field-wysiwyg" sortOrder="50" formElement="wysiwyg">
182+
<field name="description" template="ui/form/field" sortOrder="50" formElement="wysiwyg">
183183
<argument name="data" xsi:type="array">
184184
<item name="config" xsi:type="array">
185185
<item name="wysiwygConfigData" xsi:type="array">

0 commit comments

Comments
 (0)