Skip to content

Commit 1a8f914

Browse files
committed
Merge branch 'MC-5723-google-maps' of github.com:magento-obsessive-owls/magento2-page-builder into cms-team-1-delivery
# Conflicts: # app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/map/preview.js # app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/map/preview.ts
2 parents ccc8775 + df6fc4c commit 1a8f914

30 files changed

+1435
-4228
lines changed

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

Lines changed: 43 additions & 3 deletions
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

Lines changed: 7 additions & 11 deletions
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

Lines changed: 5 additions & 2 deletions
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/ContentTypeMapActionGroup.xml

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@
208208
<waitForElementVisible selector="{{page.height(index, height.value)}}" stepKey="waitForHeight"/>
209209
<waitForElementVisible selector="{{page.showControls(index, showControls.value)}}" stepKey="waitForShowControls"/>
210210
</actionGroup>
211+
<actionGroup name="validateMapSettingsWithErrorOverlay">
212+
<arguments>
213+
<argument name="page"/>
214+
<argument name="height" defaultValue="PageBuilderMapHeightDefaultProperty"/>
215+
<argument name="showControls" defaultValue="PageBuilderMapShowControls_Default"/>
216+
<argument name="index" defaultValue="1" type="string"/>
217+
</arguments>
218+
<comment userInput="validateMapSettings" stepKey="comment"/>
219+
<waitForElement selector="{{page.base(index)}}" stepKey="waitForMap"/>
220+
<waitForElement selector="{{page.height(index, height.value)}}" stepKey="waitForHeight"/>
221+
<dontSeeElement selector="{{page.height(index, height.value)}}" stepKey="dontSeeHeight"/>
222+
<seeElementInDOM selector="{{page.height(index, height.value)}}" stepKey="seeInDOMHeight"/>
223+
<waitForElement selector="{{page.showControls(index, showControls.value)}}" stepKey="waitForShowControls"/>
224+
<dontSeeElement selector="{{page.showControls(index, showControls.value)}}" stepKey="dontSeeShowControls"/>
225+
<seeElementInDOM selector="{{page.showControls(index, showControls.value)}}" stepKey="seeInDOMShowControls"/>
226+
</actionGroup>
211227
<actionGroup name="validateEmptyMapStoreFront">
212228
<arguments>
213229
<argument name="index" defaultValue="1" type="string"/>
@@ -362,21 +378,20 @@
362378
<waitForElementVisible selector="{{page.latitude(index, latitude)}}" stepKey="waitForLatitude"/>
363379
<waitForElementVisible selector="{{page.longitude(index, longitude)}}" stepKey="waitForLongitude"/>
364380
</actionGroup>
365-
<actionGroup name="dontSeeWarningMessage">
381+
<actionGroup name="validateMapErrorMessageStage">
366382
<arguments>
367-
<argument name="page" defaultValue="MapOnStage"/>
368383
<argument name="index" defaultValue="1" type="string"/>
369384
</arguments>
370-
<waitForElement selector="{{page.base(index)}}" stepKey="seeMap"/>
371-
<dontSee userInput="{{googleMapsAPIKey.warningMessage}}" stepKey="dontSeeWarningMessage"/>
385+
<waitForElement selector="{{MapOnStage.base(index)}}" stepKey="seeMap"/>
386+
<waitForElementVisible selector="{{MapOnStage.errorContainer(index)}}" stepKey="seeMapErrorContainer"/>
387+
<see userInput="{{PageBuilderMapCommonData.mapErrorMessageAdmin}}" selector="{{MapOnStage.errorContainer(index)}}" stepKey="seeMapErrorMessage"/>
372388
</actionGroup>
373-
<actionGroup name="validateMapErrorMessageStage">
389+
<actionGroup name="validateMapErrorMessageAddLocationForm">
374390
<arguments>
375391
<argument name="index" defaultValue="1" type="string"/>
376392
</arguments>
377-
<waitForElement selector="{{MapOnStage.base(index)}}" stepKey="seeMap"/>
378-
<waitForElementVisible selector="{{MapOnStage.errorContainer(index)}}" stepKey="seeMapErrorContainer"/>
379-
<see userInput="{{PageBuilderMapCommonData.mapErrorMessageStage}}" selector="{{MapOnStage.errorContainer(index)}}" stepKey="seeMapErrorMessage"/>
393+
<waitForElementVisible selector="{{AddLocationForm.errorContainer(index)}}" stepKey="seeMapErrorContainer"/>
394+
<see userInput="{{PageBuilderMapCommonData.mapErrorMessageAdmin}}" selector="{{AddLocationForm.errorContainer(index)}}" stepKey="seeMapErrorMessage"/>
380395
</actionGroup>
381396
<actionGroup name="validateMapErrorMessageStorefront">
382397
<arguments>
@@ -387,11 +402,20 @@
387402
<see userInput="{{PageBuilderMapCommonData.mapErrorTitleStorefront}}" selector="{{MapOnStorefront.errorTitle(index)}}" stepKey="seeMapErrorTitle"/>
388403
<see userInput="{{PageBuilderMapCommonData.mapErrorMessageStorefront}}" selector="{{MapOnStorefront.errorMessage(index)}}" stepKey="seeMapErrorMessage"/>
389404
</actionGroup>
390-
<actionGroup name="dontSeeRenderedMapOnLocationForm">
405+
<actionGroup name="validateWarningMessageLink">
391406
<arguments>
392-
<argument name="index" defaultValue="1" type="string"/>
407+
<argument name="section"/>
393408
</arguments>
394-
<waitForElementVisible selector="{{AddLocationForm.base(index)}}" stepKey="seeMap"/>
395-
<dontSeeElementInDOM selector="{{AddLocationForm.renderedMap}}" stepKey="dontSeeRenderedMap"/>
409+
<waitForElementVisible selector="{{section.warningMessageLink}}" stepKey="waitForWarningMessageLink"/>
410+
<click selector="{{section.warningMessageLink}}" stepKey="clickLink"/>
411+
<waitForPageLoad stepKey="waitForPageLoad"/>
412+
<seeInCurrentUrl url="{{AdminContentManagementPage.url}}#cms_pagebuilder" stepKey="validateURL"/>
413+
<seeElement selector="{{ContentManagementSection.GoogleMapsAPIKeyInputField}}" stepKey="seeGoogleMapsAPIKeyInputField"/>
414+
</actionGroup>
415+
<actionGroup name="validateAdvancedStyleWithAllUpdatedMapWithErrorOverlay" extends="validateAdvancedStyleWithAllUpdatedNotVisible">
416+
<comment userInput="removing w/ merge" stepKey="dontSeeElement"/>
417+
</actionGroup>
418+
<actionGroup name="validateAdvancedStyleWithNoAlignmentMapWithErrorOverlay" extends="validateAdvancedStyleWithNoAlignmentNotVisible">
419+
<comment userInput="removing w/ merge" stepKey="dontSeeElement"/>
396420
</actionGroup>
397421
</actionGroups>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@
9191
<actionGroup name="clickAndValidateGoogleMapsAPIKeyTestKeyButton">
9292
<arguments>
9393
<argument name="expectedResult" defaultValue="success" type="string"/>
94+
<argument name="buttonText" type="string"/>
9495
</arguments>
9596
<comment userInput="clickAndValidateGoogleMapsAPIKeyTestKeyButton" stepKey="comment"/>
9697
<waitForElementVisible selector="{{ContentManagementSection.GoogleMapsAPIKeyTestKeyButton}}" stepKey="waitForTestKeyButtonEnabled"/>
9798
<click selector="{{ContentManagementSection.GoogleMapsAPIKeyTestKeyButton}}" stepKey="clickTestKeyButton"/>
9899
<waitForPageLoad stepKey="waitForPageLoad"/>
99-
<waitForElementVisible selector="{{ContentManagementSection.GoogleMapsAPIKeyTestKeyResult(expectedResult)}}" stepKey="waitForTestKeyButtonResult"/>
100+
<waitForElementVisible selector="{{ContentManagementSection.GoogleMapsAPIKeyTestKeyResult}} .icon-admin-pagebuilder-{{expectedResult}}" stepKey="waitForTestKeyButtonResult"/>
101+
<see userInput="{{buttonText}}" selector="{{ContentManagementSection.GoogleMapsAPIKeyTestKeyResult}}" stepKey="seeTestKeyButtonText"/>
100102
</actionGroup>
101103
<actionGroup name="inputGoogleMapsStyle">
102104
<arguments>

app/code/Magento/PageBuilder/Test/Mftf/Data/CmsConfigData.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
<data key="row">row_cms_pagebuilder_google_maps_api_key</data>
1414
<data key="label">Google Maps API Key</data>
1515
<data key="default"/>
16-
<data key="valid">AIzaSyCw10cOO31cpxb2bcwnHPHKtxov8oUbxJw</data>
16+
<data key="valid">AIzaSyA7TbgpW4U9yKFNzJmHPwLUh_bWt9nXBl4</data>
1717
<data key="invalidOneCharacter">a</data>
18-
<data key="invalidOneCharacterOffOfValid">aIzaSyCw10cOO31cpxb2bcwnHPHKtxov8oUbxJw</data>
18+
<data key="invalidOneCharacterOffOfValid">aIzaSyA7TbgpW4U9yKFNzJmHPwLUh_bWt9nXBl4</data>
1919
<data key="empty"/>
2020
<data key="warningMessage">You must provide the Google Maps API key in order to use the map</data>
21+
<data key="keyButtonText">Test Key</data>
22+
<data key="invalidKeyButtonText">Key is invalid. Try a different key.</data>
23+
<data key="validKeyButtonText">Key is valid</data>
2124
</entity>
2225
<entity name="googleMapsStyle" type="config">
2326
<data key="section">cms_pagebuilder</data>

app/code/Magento/PageBuilder/Test/Mftf/Data/MapData.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<entity name="PageBuilderMapCommonData" type="pagebuilder__map_common_data">
2525
<data key="mapErrorTitleStorefront">Oops! Something went wrong.</data>
2626
<data key="mapErrorMessageStorefront">This page didn't load Google Maps correctly. See the JavaScript console for technical details.</data>
27-
<data key="mapErrorMessageStage">Enter API Key to use Google Maps</data>
27+
<data key="mapErrorMessageAdmin">You must provide a valid Google Maps API key to use a map.</data>
2828
</entity>
2929
<!-- Map Position -->
3030
<entity name="PageBuilderMapPositionDefaultProperty" type="pagebuilder_map_position_property">

app/code/Magento/PageBuilder/Test/Mftf/Section/ContentManagementSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<element name="ConfigurationFieldLabel" type="button" selector="//div[contains(@class,'form-inline')]//fieldset[@id='{{arg1}}']//tr[@id='{{arg2}}']//span[.='{{arg3}}']" parameterized="true"/>
2121
<element name="GoogleMapsAPIKeyInputField" type="input" selector="#cms_pagebuilder_google_maps_api_key"/>
2222
<element name="GoogleMapsAPIKeyTestKeyButton" type="button" selector="#cms_pagebuilder_google_maps_api_key_validator"/>
23-
<element name="GoogleMapsAPIKeyTestKeyResult" type="button" selector="#cms_pagebuilder_google_maps_api_key_validator .result .icon-admin-pagebuilder-{{arg1}}" parameterized="true"/>
23+
<element name="GoogleMapsAPIKeyTestKeyResult" type="button" selector="#cms_pagebuilder_google_maps_api_key_validator .result"/>
2424
<element name="GoogleMapsAPIKeyHelperText" type="text" selector="#row_cms_pagebuilder_google_maps_api_key .value .note span"/>
2525
<element name="GoogleMapsGetAPIKeyLink" type="button" selector="#row_cms_pagebuilder_google_maps_api_key a[href]"/>
2626
<element name="GoogleMapsStyleInputField" type="input" selector="#cms_pagebuilder_google_maps_style"/>

0 commit comments

Comments
 (0)