Skip to content

Commit fb522db

Browse files
authored
Merge pull request #184 from magento-obsessive-owls/cms-team-1-delivery
[Owls] Beta Release #3
2 parents 28a01e8 + 0340fb0 commit fb522db

File tree

135 files changed

+3493
-7133
lines changed

Some content is hidden

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

135 files changed

+3493
-7133
lines changed

app/code/Magento/PageBuilder/Block/GoogleMapsApi.php

+43-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
namespace Magento\PageBuilder\Block;
99

10+
use Magento\Framework\View\Element\Template;
11+
1012
/**
13+
* Google Maps API Block
14+
*
1115
* @api
1216
*/
1317
class GoogleMapsApi extends \Magento\Framework\View\Element\Template
@@ -16,16 +20,24 @@ class GoogleMapsApi extends \Magento\Framework\View\Element\Template
1620
const GOOGLE_MAPS_LIBRARY_URL = 'https://maps.googleapis.com/maps/api/js?v=3&key=%s';
1721
const GOOGLE_MAPS_STYLE_PATH = 'cms/pagebuilder/google_maps_style';
1822

23+
/**
24+
* Retrieve the Google Maps API key
25+
*
26+
* @return string
27+
*/
28+
public function getApiKey(): ?string
29+
{
30+
return $this->_scopeConfig->getValue(self::GOOGLE_MAPS_API_KEY_PATH);
31+
}
32+
1933
/**
2034
* Generate URL for retrieving Google Maps Javascript API
2135
*
2236
* @return string
2337
*/
2438
public function getLibraryUrl(): string
2539
{
26-
$apiKey = $this->_scopeConfig->getValue(self::GOOGLE_MAPS_API_KEY_PATH);
27-
$libraryUrlWithKey = sprintf(self::GOOGLE_MAPS_LIBRARY_URL, $apiKey);
28-
return $libraryUrlWithKey;
40+
return sprintf(self::GOOGLE_MAPS_LIBRARY_URL, $this->getApiKey());
2941
}
3042

3143
/**
@@ -37,4 +49,32 @@ public function getStyle(): ?string
3749
{
3850
return $this->_scopeConfig->getValue(self::GOOGLE_MAPS_STYLE_PATH);
3951
}
52+
53+
/**
54+
* Return the translated message for an invalid API key.
55+
*
56+
* @return \Magento\Framework\Phrase
57+
*/
58+
public function getInvalidApiKeyMessage(): \Magento\Framework\Phrase
59+
{
60+
return __(
61+
"You must provide a valid <a href='%1'>Google Maps API key</a> to use a map.",
62+
$this->_urlBuilder->getUrl('adminhtml/system_config/edit/section/cms', ['_fragment' => 'cms_pagebuilder'])
63+
);
64+
}
65+
66+
/**
67+
* Include the Google Maps library within the admin only if the API key is set
68+
*
69+
* @return bool
70+
*/
71+
public function shouldIncludeGoogleMapsLibrary(): bool
72+
{
73+
try {
74+
return $this->_appState->getAreaCode() !== \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE ||
75+
$this->getApiKey();
76+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
77+
return false;
78+
}
79+
}
4080
}

app/code/Magento/PageBuilder/Component/GoogleMapsApiKeyValidationContainer.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\PageBuilder\Model\GoogleMaps\ApiKeyValidator;
1515

1616
/**
17+
* Google Maps API Key Validation Container for UI Component Form
18+
*
1719
* @api
1820
*/
1921
class GoogleMapsApiKeyValidationContainer extends \Magento\Ui\Component\Container
@@ -30,26 +32,19 @@ class GoogleMapsApiKeyValidationContainer extends \Magento\Ui\Component\Containe
3032
*/
3133
private $scopeConfig;
3234

33-
/**
34-
* @var ApiKeyValidator
35-
*/
36-
private $apiKeyValidator;
37-
3835
/**
3936
* Constructor
4037
*
4138
* @param ContextInterface $context
4239
* @param UrlInterface $url
4340
* @param ScopeConfigInterface $scopeConfig
44-
* @param ApiKeyValidator $apiKeyValidator
4541
* @param array $components
4642
* @param array $data
4743
*/
4844
public function __construct(
4945
ContextInterface $context,
5046
UrlInterface $url,
5147
ScopeConfigInterface $scopeConfig,
52-
ApiKeyValidator $apiKeyValidator,
5348
array $components = [],
5449
array $data = []
5550
) {
@@ -60,7 +55,6 @@ public function __construct(
6055
);
6156
$this->url = $url;
6257
$this->scopeConfig = $scopeConfig;
63-
$this->apiKeyValidator = $apiKeyValidator;
6458
}
6559

6660
/**
@@ -73,13 +67,15 @@ public function prepare()
7367
parent::prepare();
7468
$config = $this->getData('config');
7569
$apiKey = $this->scopeConfig->getValue(self::GOOGLE_MAPS_API_KEY_PATH) ?: "";
76-
$response = $this->apiKeyValidator->validate($apiKey);
77-
if (!$response['success']) {
70+
if (trim($apiKey) == "") {
7871
$config['visible'] = true;
7972
}
8073

8174
if (isset($config['map_configuration_url'])) {
82-
$config['map_configuration_url'] = $this->url->getUrl($config['map_configuration_url']);
75+
$config['map_configuration_url'] = $this->url->getUrl(
76+
$config['map_configuration_url'],
77+
['_fragment' => 'cms_pagebuilder']
78+
);
8379
}
8480
if (isset($config['content'])) {
8581
$config['content'] = sprintf($config['content'], $config['map_configuration_url']);

app/code/Magento/PageBuilder/Controller/Adminhtml/GoogleMaps/ValidateApi.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
use Magento\Framework\Controller\ResultFactory;
1111

12-
class ValidateApi extends \Magento\Backend\App\Action
12+
/**
13+
* Class ValidateApi
14+
*/
15+
class ValidateApi extends \Magento\Backend\App\Action implements \Magento\Framework\App\Action\HttpPostActionInterface
1316
{
1417
const ADMIN_RESOURCE = 'Magento_Backend::content';
1518

@@ -39,7 +42,7 @@ public function __construct(
3942
*/
4043
public function execute()
4144
{
42-
$apiKey = $this->getRequest()->getParam('key');
45+
$apiKey = $this->getRequest()->getParam('googleMapsApiKey');
4346
$validationResult = $this->apiKeyValidator->validate($apiKey);
4447
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($validationResult);
4548
}

app/code/Magento/PageBuilder/Test/Mftf/ActionGroup/ContentTypeBlockActionGroup.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@
4444
<argument name="minHeight"/>
4545
<argument name="padding"/>
4646
<argument name="index" defaultValue="1" type="string"/>
47-
<!-- Remove storefrontBugOffset when MC-5079 is resolved -->
48-
<argument name="storefrontBugOffset" defaultValue="0" type="string"/>
4947
</arguments>
5048
<executeJS function="return document.querySelectorAll('{{block.baseCSS}} {{container.baseCSS}}')[{{index}}-1].clientHeight;" stepKey="containerHeight"/>
51-
<executeJS function="return {$containerHeight}-{{storefrontBugOffset}}" stepKey="minusBugOffset"/>
5249
<assertGreaterThanOrEqual stepKey="assertContainerHeightGreaterThanOrEqualMinHeight">
5350
<expectedResult type="string">{{minHeight}}</expectedResult>
54-
<actualResult type="variable">minusBugOffset</actualResult>
51+
<actualResult type="variable">containerHeight</actualResult>
5552
</assertGreaterThanOrEqual>
5653
<executeJS function="return document.querySelectorAll('{{block.baseCSS}} {{container.baseCSS}}')[{{index}}-1].getBoundingClientRect().bottom-{{padding.paddingBottom}}" stepKey="containerBottomPositionMinusPadding"/>
5754
<executeJS function="return document.querySelectorAll('{{block.baseCSS}} {{content.baseCSS}}')[{{index}}-1].getBoundingClientRect().bottom" stepKey="contentBottomPosition"/>

0 commit comments

Comments
 (0)