Skip to content

Commit a8325c6

Browse files
authored
Merge pull request #74 from magento-obsessive-owls/cms-team-2-sprint-9
[CMS Team 2 - Sprint 9] Maps Location, Stacked Buttons, and Button Test Coverage
2 parents d2cc570 + df7f6ea commit a8325c6

File tree

96 files changed

+8815
-3248
lines changed

Some content is hidden

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

96 files changed

+8815
-3248
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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\Adminhtml\ContentType\Edit;
10+
11+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
12+
13+
class CancelButton implements ButtonProviderInterface
14+
{
15+
/**
16+
* @var string
17+
*/
18+
private $targetName;
19+
20+
/**
21+
* Constructor
22+
*
23+
* @param $targetName
24+
*/
25+
public function __construct(string $targetName)
26+
{
27+
$this->targetName = $targetName;
28+
}
29+
30+
/**
31+
* Retrieve button data
32+
*
33+
* @return array
34+
*/
35+
public function getButtonData(): array
36+
{
37+
return [
38+
'label' => __('Cancel'),
39+
'class' => 'cancel',
40+
'on_click' => '',
41+
'data_attribute' => [
42+
'mage-init' => [
43+
'buttonAdapter' => [
44+
'actions' => [
45+
[
46+
'targetName' => $this->targetName,
47+
'actionName' => 'closeModal',
48+
'params' => [
49+
false,
50+
]
51+
]
52+
]
53+
]
54+
],
55+
'form-role' => 'cancel',
56+
],
57+
'sort_order' => 90
58+
];
59+
}
60+
}

app/code/Magento/PageBuilder/Block/Adminhtml/ContentType/Edit/Close.php renamed to app/code/Magento/PageBuilder/Block/Adminhtml/ContentType/Edit/CloseButton.php

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

810
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
911

10-
class Close implements ButtonProviderInterface
12+
class CloseButton implements ButtonProviderInterface
1113
{
1214
/**
1315
* @var string

app/code/Magento/PageBuilder/Setup/DataConverter/Renderer/Buttons.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ public function render(array $itemData, array $additionalData = [])
4444

4545
$rootElementAttributes = [
4646
'data-role' => 'buttons',
47-
'data-appearance' => 'default',
48-
'class' => $eavData['css_classes'] ?? ''
47+
'data-appearance' => 'inline',
48+
'class' => $eavData['css_classes'] ?? '',
49+
'style' => 'display: inline-block;'
4950
];
5051

5152
if (isset($itemData['formData'])) {
5253
$style = $this->styleExtractor->extractStyle($itemData['formData']);
5354
if (strpos($style, 'padding') === false) {
5455
$style .= ($style ? ' ' : '') . 'padding: 10px 10px 0px;';
5556
}
56-
$rootElementAttributes['style'] = $style;
57+
$rootElementAttributes['style'] .= ' ' . $style;
5758
}
5859

5960
$rootElementHtml = '<div';

app/code/Magento/PageBuilder/Setup/DataConverter/Renderer/Map.php

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class Map implements RendererInterface
2424
*/
2525
private $eavAttributeLoader;
2626

27+
/**
28+
* @var array
29+
*/
30+
private $rootElementAttributes;
31+
2732
public function __construct(
2833
StyleExtractorInterface $styleExtractor,
2934
EavAttributeLoaderInterface $eavAttributeLoader
@@ -42,26 +47,21 @@ public function render(array $itemData, array $additionalData = [])
4247
}
4348
$eavData = $this->eavAttributeLoader->load($itemData['entityId']);
4449

45-
$rootElementAttributes = [
50+
$this->rootElementAttributes = [
4651
'data-role' => 'map',
4752
'data-appearance' => 'default',
4853
'class' => $eavData['css_classes'] ?? '',
4954
'data-show-controls' => 'true',
50-
'data-position' => '{}',
55+
'data-locations' => '[]',
5156
];
5257

53-
if (isset($eavData['map'])) {
54-
$map = explode(',', $eavData['map']);
55-
$rootElementAttributes['data-position'] = '{&quot;lat&quot;:'
56-
. $map[0]
57-
. ',&quot;lng&quot;:'
58-
. $map[1]
59-
. '}';
60-
}
58+
$this->renderMapLocations($eavData);
6159

6260
if (isset($itemData['formData'])) {
6361
$formData = $itemData['formData'];
64-
$formData['height'] = $eavData['map_height'] ?? '300px';
62+
$formData['height'] = $eavData['map_height']
63+
&& strpos($eavData['map_height'], '%') === false
64+
? $eavData['map_height'] : '300px';
6565

6666
$style = $this->styleExtractor->extractStyle($formData);
6767
if ($style) {
@@ -70,16 +70,33 @@ public function render(array $itemData, array $additionalData = [])
7070
} else {
7171
$style .= ' display: none;';
7272
}
73-
$rootElementAttributes['style'] = $style;
73+
$this->rootElementAttributes['style'] = $style;
7474
}
7575
}
7676

7777
$rootElementHtml = '<div';
78-
foreach ($rootElementAttributes as $attributeName => $attributeValue) {
78+
foreach ($this->rootElementAttributes as $attributeName => $attributeValue) {
7979
$rootElementHtml .= $attributeValue !== '' ? " $attributeName=\"$attributeValue\"" : '';
8080
}
8181
$rootElementHtml .= '></div>';
8282

8383
return $rootElementHtml;
8484
}
85+
86+
/**
87+
* Extract and render Map Location data from EAV
88+
*
89+
* @param array $eavData
90+
*/
91+
private function renderMapLocations($eavData)
92+
{
93+
if (isset($eavData['map'])) {
94+
$map = explode(',', $eavData['map']);
95+
$this->rootElementAttributes['data-locations'] = '[{&quot;position&quot;:{&quot;latitude&quot;:'
96+
. $map[0]
97+
. ',&quot;longitude&quot;:'
98+
. $map[1]
99+
. '}}]';
100+
}
101+
}
85102
}

0 commit comments

Comments
 (0)