Skip to content

Commit 7030af0

Browse files
committed
Merge remote-tracking branch 'origin/develop' into MC-969-slide-attributes
2 parents d907ba4 + 6c7d879 commit 7030af0

File tree

204 files changed

+11886
-7286
lines changed

Some content is hidden

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

204 files changed

+11886
-7286
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\PageBuilder\Block;
10+
11+
use Magento\Framework\View\Element\Template;
12+
use Magento\Framework\DataObject;
13+
14+
/**
15+
* @api
16+
*/
17+
class WysiwygSetup extends Template
18+
{
19+
/**
20+
* @var \Magento\Ui\Component\Wysiwyg\ConfigInterface
21+
*/
22+
private $config;
23+
24+
/**
25+
* @param Template\Context $context
26+
* @param \Magento\Ui\Component\Wysiwyg\ConfigInterface $config
27+
* @param array $data
28+
*/
29+
public function __construct(
30+
\Magento\Framework\View\Element\Template\Context $context,
31+
\Magento\Ui\Component\Wysiwyg\ConfigInterface $config,
32+
array $data = []
33+
) {
34+
$this->config = $config;
35+
parent::__construct($context, $data);
36+
}
37+
38+
/**
39+
* Get config for wysiwyg initialization
40+
*
41+
* @return string
42+
*/
43+
public function getConfigJson() : string
44+
{
45+
$config = $this->config->getConfig();
46+
47+
if (is_array($config)) {
48+
$config = new DataObject($config);
49+
}
50+
51+
return $config->toJson();
52+
}
53+
}

app/code/Magento/PageBuilder/Controller/Adminhtml/ContentType/Image/Upload.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class Upload extends \Magento\Backend\App\Action
3636
*/
3737
private $storeManager;
3838

39+
/**
40+
* @var \Magento\Cms\Helper\Wysiwyg\Images
41+
*/
42+
private $cmsWysiwygImages;
43+
3944
/**
4045
* Constructor
4146
*
@@ -44,19 +49,22 @@ class Upload extends \Magento\Backend\App\Action
4449
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4550
* @param \Magento\Framework\File\UploaderFactory $uploaderFactory
4651
* @param \Magento\Framework\Filesystem\DirectoryList $directoryList
52+
* @param \Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages
4753
*/
4854
public function __construct(
4955
\Magento\Backend\App\Action\Context $context,
5056
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
5157
\Magento\Store\Model\StoreManagerInterface $storeManager,
5258
\Magento\Framework\File\UploaderFactory $uploaderFactory,
53-
\Magento\Framework\Filesystem\DirectoryList $directoryList
59+
\Magento\Framework\Filesystem\DirectoryList $directoryList,
60+
\Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages
5461
) {
5562
parent::__construct($context);
5663
$this->resultJsonFactory = $resultJsonFactory;
5764
$this->storeManager = $storeManager;
5865
$this->uploaderFactory = $uploaderFactory;
5966
$this->directoryList = $directoryList;
67+
$this->cmsWysiwygImages = $cmsWysiwygImages;
6068
}
6169

6270
/**
@@ -89,6 +97,7 @@ public function execute()
8997
try {
9098
$result = $fileUploader->save($this->getUploadDir());
9199
$baseUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
100+
$result['id'] = $this->cmsWysiwygImages->idEncode($result['file']);
92101
$result['url'] = $baseUrl . $this->getFilePath(self::UPLOAD_DIR, $result['file']);
93102
} catch (\Exception $e) {
94103
$result = [
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\PageBuilder\Model\Config\ContentType\AdditionalData\Provider\Wysiwyg;
9+
10+
use Magento\PageBuilder\Model\Config\ContentType\AdditionalData\ProviderInterface;
11+
12+
/**
13+
* Returns adapter config based on active editor path
14+
*/
15+
class Config implements ProviderInterface
16+
{
17+
/**
18+
* @var \Magento\Cms\Model\Wysiwyg\Config
19+
*/
20+
private $wysiwygConfig;
21+
22+
/**
23+
* @var \Magento\PageBuilder\Model\Wysiwyg\InlineEditingSupportedAdapterList
24+
*/
25+
private $inlineEditingChecker;
26+
27+
/**
28+
* @var \Magento\Ui\Block\Wysiwyg\ActiveEditor
29+
*/
30+
private $activeEditor;
31+
32+
/**
33+
* @var array
34+
*/
35+
private $additionalConfig;
36+
37+
/**
38+
* Config constructor.
39+
* @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig
40+
* @param \Magento\PageBuilder\Model\Wysiwyg\InlineEditingSupportedAdapterList $inlineEditingChecker
41+
* @param \Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor
42+
* @param array $additionalConfig
43+
*/
44+
public function __construct(
45+
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
46+
\Magento\PageBuilder\Model\Wysiwyg\InlineEditingSupportedAdapterList $inlineEditingChecker,
47+
\Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor,
48+
$additionalConfig = []
49+
) {
50+
$this->wysiwygConfig = $wysiwygConfig;
51+
$this->inlineEditingChecker = $inlineEditingChecker;
52+
$this->activeEditor = $activeEditor;
53+
$this->additionalConfig = $additionalConfig;
54+
}
55+
56+
/**
57+
* @inheritdoc
58+
*/
59+
public function getData(string $itemName) : array
60+
{
61+
$config = [];
62+
$activeEditorPath = $this->activeEditor->getWysiwygAdapterPath();
63+
if ($this->inlineEditingChecker->isSupported($activeEditorPath)) {
64+
$config['adapter'] = $this->wysiwygConfig->getConfig()->getData();
65+
if (isset($this->additionalConfig[$activeEditorPath])) {
66+
$config['additional'] = $this->additionalConfig[$activeEditorPath];
67+
}
68+
}
69+
return [$itemName => $config,];
70+
}
71+
}

app/code/Magento/PageBuilder/Model/Config/ContentType/Converter.php

Lines changed: 58 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
class Converter implements \Magento\Framework\Config\ConverterInterface
1414
{
15+
const DEFAULT_ATTRIBUTE_READER = 'Magento_PageBuilder/js/property/attribute-reader';
16+
const DEFAULT_PROPERTY_READER = 'Magento_PageBuilder/js/property/style-property-reader';
17+
1518
/**
1619
* @var ArgumentParser
1720
*/
@@ -122,18 +125,19 @@ private function convertAppearanceData(\DOMElement $appearanceNode): array
122125
$appearanceData = [];
123126
$appearanceData = array_merge(
124127
$appearanceData,
125-
$this->convertAppearanceProperties($appearanceNode)
128+
$this->convertAppearanceStyles($appearanceNode)
126129
);
127130
$readerNode = $appearanceNode->getElementsByTagName('reader')->item(0);
128131
if ($readerNode && $readerNode->nodeValue) {
129132
$appearanceData['readers'] = [$readerNode->nodeValue];
130133
} else {
131134
$appearanceData['readers'] = $this->convertAppearanceReaders($appearanceNode);
132135
}
133-
$dataMappingNode = $appearanceNode->getElementsByTagName('data_mapping')->item(0);
134-
if ($dataMappingNode) {
135-
$appearanceData['data_mapping'] = $this->convertDataMapping($dataMappingNode);
136+
$elementsNode = $appearanceNode->getElementsByTagName('elements')->item(0);
137+
if ($elementsNode) {
138+
$appearanceData['elements'] = $this->convertElements($elementsNode);
136139
}
140+
$appearanceData['converters'] = $this->convertConvertersData($appearanceNode);
137141
$appearanceData['preview_template'] = $this->getAttributeValue($appearanceNode, 'preview_template');
138142
$appearanceData['render_template'] = $this->getAttributeValue($appearanceNode, 'render_template');
139143
$appearanceData['reader'] = $this->getAttributeValue($appearanceNode, 'reader');
@@ -151,7 +155,7 @@ private function convertAppearanceData(\DOMElement $appearanceNode): array
151155
* @param \DOMElement $elementNode
152156
* @return array
153157
*/
154-
private function convertAppearanceProperties(\DOMElement $elementNode): array
158+
private function convertAppearanceStyles(\DOMElement $elementNode): array
155159
{
156160
$data = [];
157161
foreach ($elementNode->getElementsByTagName('data') as $dataNode) {
@@ -200,31 +204,26 @@ private function validateAppearanceConfig(array $appearanceConfig)
200204
}
201205

202206
/**
203-
* Convert data mapping
207+
* Convert elements
204208
*
205209
* @param \DOMElement $childNode
206210
* @return array
207211
*/
208-
private function convertDataMapping(\DOMElement $childNode): array
212+
private function convertElements(\DOMElement $childNode): array
209213
{
210214
$elementData = [];
211215
foreach ($childNode->getElementsByTagName('element') as $elementNode) {
212216
$elementName = $elementNode->attributes->getNamedItem('name')->nodeValue;
213217
$elementData[$elementName] = [
214-
'style' => $this->convertProperties($elementNode),
218+
'style' => $this->convertStyles($elementNode),
215219
'attributes' => $this->convertAttributes($elementNode),
216220
'html' => $this->convertHtml($elementNode),
217221
'css' => $this->convertCss($elementNode),
218222
'tag' => $this->convertTag($elementNode)
219223
];
220224
}
221225

222-
$converters = $this->convertConvertersData($childNode);
223-
224-
return [
225-
'elements' => $elementData,
226-
'converters' => $converters
227-
];
226+
return $elementData;
228227
}
229228

230229
/**
@@ -259,45 +258,35 @@ private function convertAdditionalData(\DOMElement $elementNode): array
259258
}
260259

261260
/**
262-
* Convert properties
261+
* Convert styles
263262
*
264263
* @param \DOMElement $elementNode
265264
* @return array
266265
*/
267-
private function convertProperties(\DOMElement $elementNode): array
266+
private function convertStyles(\DOMElement $elementNode): array
268267
{
269-
$propertiesData = [];
270-
$propertiesNode = $elementNode->getElementsByTagName('style_properties')->item(0);
271-
if ($propertiesNode) {
272-
foreach ($propertiesNode->getElementsByTagName('property') as $propertyNode) {
273-
$propertiesData[] = [
274-
'var' => $this->extractVariableName($propertyNode),
275-
'name' => $this->getAttributeValue($propertyNode, 'source'),
276-
'converter' => $this->getAttributeValue($propertyNode, 'converter'),
277-
'preview_converter' => $this->getAttributeValue($propertyNode, 'preview_converter'),
278-
'virtual' => $this->getAttributeValue($propertyNode, 'virtual'),
279-
'persist' => $this->getAttributeValue($propertyNode, 'persist'),
280-
];
281-
}
282-
foreach ($propertiesNode->getElementsByTagName('complex_property') as $propertyNode) {
283-
$propertiesData[] = [
284-
'var' => $this->extractVariableName($propertyNode),
285-
'reader' => $this->getAttributeValue($propertyNode, 'reader'),
286-
'converter' => $this->getAttributeValue($propertyNode, 'converter'),
287-
'preview_converter' => $this->getAttributeValue($propertyNode, 'preview_converter'),
288-
'virtual' => $this->getAttributeValue($propertyNode, 'virtual'),
289-
'complex' => true
290-
];
291-
}
292-
foreach ($propertiesNode->getElementsByTagName('static_property') as $propertyNode) {
293-
$propertiesData[] = [
294-
'name' => $this->getAttributeValue($propertyNode, 'source'),
295-
'value' => $this->getAttributeValue($propertyNode, 'value'),
296-
'static' => true
297-
];
298-
}
268+
$stylesData = [];
269+
foreach ($elementNode->getElementsByTagName('style') as $styleNode) {
270+
$stylesData[] = [
271+
'var' => $this->extractVariableName($styleNode),
272+
'name' => $this->getAttributeValue($styleNode, 'source'),
273+
'converter' => $this->getAttributeValue($styleNode, 'converter'),
274+
'preview_converter' => $this->getAttributeValue($styleNode, 'preview_converter'),
275+
'persistence_mode' => $this->getAttributeValue($styleNode, 'persistence_mode')
276+
?? 'readwrite',
277+
'reader' => $this->getAttributeValue($styleNode, 'reader')
278+
?? self::DEFAULT_PROPERTY_READER,
279+
];
280+
}
281+
foreach ($elementNode->getElementsByTagName('static_style') as $styleNode) {
282+
$stylesData[] = [
283+
'name' => $this->getAttributeValue($styleNode, 'source'),
284+
'value' => $this->getAttributeValue($styleNode, 'value'),
285+
'static' => true
286+
];
299287
}
300-
return $propertiesData;
288+
289+
return $stylesData;
301290
}
302291

303292
/**
@@ -309,37 +298,26 @@ private function convertProperties(\DOMElement $elementNode): array
309298
private function convertAttributes(\DOMElement $elementNode): array
310299
{
311300
$attributesData = [];
312-
$attributesNode = $elementNode->getElementsByTagName('attributes')->item(0);
313-
if ($attributesNode) {
314-
foreach ($attributesNode->getElementsByTagName('attribute') as $attributeNode) {
315-
$attributesData[] = [
316-
'var' => $this->extractVariableName($attributeNode),
317-
'name' => $this->getAttributeValue($attributeNode, 'source'),
318-
'converter' => $this->getAttributeValue($attributeNode, 'converter'),
319-
'preview_converter' => $this->getAttributeValue($attributeNode, 'preview_converter'),
320-
'virtual' => $this->getAttributeValue($attributeNode, 'virtual'),
321-
'persist' => $this->getAttributeValue($attributeNode, 'persist'),
322-
];
323-
}
324-
foreach ($attributesNode->getElementsByTagName('static_attribute') as $attributeNode) {
325-
$attributesData[] = [
326-
'name' => $this->getAttributeValue($attributeNode, 'source'),
327-
'value' => $this->getAttributeValue($attributeNode, 'value'),
328-
'static' => true
329-
];
330-
}
331-
foreach ($attributesNode->getElementsByTagName('complex_attribute') as $attributeNode) {
332-
$attributesData[] = [
333-
'var' => $this->extractVariableName($attributeNode),
334-
'reader' => $this->getAttributeValue($attributeNode, 'reader'),
335-
'converter' => $this->getAttributeValue($attributeNode, 'converter'),
336-
'preview_converter' => $this->getAttributeValue($attributeNode, 'preview_converter'),
337-
'virtual' => $this->getAttributeValue($attributeNode, 'virtual'),
338-
'complex' => true,
339-
'persist' => $this->getAttributeValue($attributeNode, 'persist'),
340-
];
341-
}
301+
foreach ($elementNode->getElementsByTagName('attribute') as $attributeNode) {
302+
$attributesData[] = [
303+
'var' => $this->extractVariableName($attributeNode),
304+
'name' => $this->getAttributeValue($attributeNode, 'source'),
305+
'converter' => $this->getAttributeValue($attributeNode, 'converter'),
306+
'preview_converter' => $this->getAttributeValue($attributeNode, 'preview_converter'),
307+
'persistence_mode' => $this->getAttributeValue($attributeNode, 'persistence_mode')
308+
?? 'readwrite',
309+
'reader' => $this->getAttributeValue($attributeNode, 'reader')
310+
?? self::DEFAULT_ATTRIBUTE_READER,
311+
];
342312
}
313+
foreach ($elementNode->getElementsByTagName('static_attribute') as $attributeNode) {
314+
$attributesData[] = [
315+
'name' => $this->getAttributeValue($attributeNode, 'source'),
316+
'value' => $this->getAttributeValue($attributeNode, 'value'),
317+
'static' => true
318+
];
319+
}
320+
343321
return $attributesData;
344322
}
345323

@@ -407,9 +385,9 @@ private function convertTag(\DOMElement $elementNode): array
407385
* @param \DOMElement $childNode
408386
* @return array
409387
*/
410-
private function convertConvertersData(\DOMElement $childNode): array
388+
private function convertConvertersData(\DOMElement $appearanceNode): array
411389
{
412-
$convertersNode = $childNode->getElementsByTagName('converters')->item(0);
390+
$convertersNode = $appearanceNode->getElementsByTagName('converters')->item(0);
413391
$converters = [];
414392
if ($convertersNode) {
415393
foreach ($convertersNode->getElementsByTagName('converter') as $converterNode) {
@@ -578,7 +556,7 @@ private function getAttributeValue(\DOMElement $attributeNode, $attributeName)
578556
}
579557

580558
/**
581-
* Extract variable name from property and attribute nodes
559+
* Extract variable name from style and attribute nodes
582560
*
583561
* @param \DOMElement $node
584562
* @return string

0 commit comments

Comments
 (0)