Skip to content

Commit 53219e1

Browse files
authored
fix wrong container parameter determination, see #150 (#157)
1 parent 5ac9242 commit 53219e1

File tree

7 files changed

+43
-21
lines changed

7 files changed

+43
-21
lines changed

UPGRADE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Just click the "update" button or execute the migration command to finish the bu
1111
- **[IMPROVEMENT]**: use no-cookie domain for youtube videos [@ghettopro](https://github.com/dachcom-digital/pimcore-toolbox/pull/153)
1212
- **[BUG FIX]**: Fix invalid asset video markup [@gpalmisano](https://github.com/dachcom-digital/pimcore-toolbox/pull/154)
1313
- **[BUG FIX]**: Fix google maps locations with single quotes [#151](https://github.com/dachcom-digital/pimcore-toolbox/issues/151)
14+
- **[BUG FIX]**: Fix wrong container parameter concatenation [#150](https://github.com/dachcom-digital/pimcore-toolbox/issues/150)
1415

1516
#### Update from Version 3.2.4 to Version 3.2.5
1617
- **[BUG FIX]**: Fix column adjuster column_store availability check

docs/11_ElementsOverview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,16 @@ parameters:
209209
```
210210

211211
#### III. Direct Element Configuration
212-
If you don't want do define them via parameters, you need to override the default parameters
212+
If you don't want to define them via parameters, you need to override the default parameters
213213
on configuration layer:
214214

215215
```yaml
216216
toolbox:
217217
areas:
218218
googleMap:
219219
config_parameter:
220-
map_api_key: '%toolbox.google_maps.browser_api_key%' # replace here
221-
simple_api_key: '%toolbox.google_maps.simple_api_key%' # replace here
220+
map_api_key: null # replace here
221+
simple_api_key: null # replace here
222222
```
223223

224224
### Script Integration

src/ToolboxBundle/DependencyInjection/ToolboxExtension.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class ToolboxExtension extends Extension implements PrependExtensionInterface
2727
*/
2828
public function prepend(ContainerBuilder $container)
2929
{
30-
$container->setParameter('toolbox.google_maps.browser_api_key', null);
31-
$container->setParameter('toolbox.google_maps.simple_api_key', null);
32-
3330
$selfConfigs = $container->getExtensionConfig($this->getAlias());
3431

3532
$rootConfigs = [];

src/ToolboxBundle/Model/Document/Tag/GoogleMap.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,39 @@ public function getId()
220220
*/
221221
protected function geocodeLocation($location)
222222
{
223+
if ($this->googleLookUpIsDisabled()) {
224+
return $location;
225+
}
226+
223227
/** @var ConfigManager $configManager */
224228
$configManager = \Pimcore::getContainer()->get(ConfigManager::class);
225229
$configNode = $configManager->setAreaNameSpace(ConfigManagerInterface::AREABRICK_NAMESPACE_INTERNAL)->getAreaParameterConfig('googleMap');
226230

227231
$address = $location['street'] . '+' . $location['zip'] . '+' . $location['city'] . '+' . $location['country'];
228232
$address = urlencode($address);
229233

230-
$key = '';
234+
$key = null;
235+
$keyParam = '';
236+
237+
$fallbackSimpleKey = \Pimcore::getContainer()->getParameter('toolbox.google_maps.simple_api_key');
238+
$fallbackBrowserKey = \Pimcore::getContainer()->getParameter('toolbox.google_maps.browser_api_key');
239+
231240
// first try to get server-api-key
232241
if (!empty($configNode) && isset($configNode['simple_api_key']) && !empty($configNode['simple_api_key'])) {
233-
$key = '&key=' . $configNode['simple_api_key'];
234-
}
235-
// if not set, get browser-api-key
236-
if ($key === '' && !empty($configNode) && isset($configNode['map_api_key']) && !empty($configNode['map_api_key'])) {
237-
$key = '&key=' . $configNode['map_api_key'];
242+
$key = $configNode['simple_api_key'];
243+
} elseif (!empty($fallbackSimpleKey)) {
244+
$key = $fallbackSimpleKey;
245+
} elseif (!empty($configNode) && isset($configNode['map_api_key']) && !empty($configNode['map_api_key'])) {
246+
$key = $configNode['map_api_key'];
247+
} elseif (!empty($fallbackBrowserKey)) {
248+
$key = $fallbackBrowserKey;
238249
}
239250

240-
if ($this->googleLookUpIsDisabled()) {
241-
return $location;
251+
if ($key !== null) {
252+
$keyParam = sprintf('&key=%s', $key);
242253
}
243254

244-
$url = 'https://maps.google.com/maps/api/geocode/json?address=' . $address . $key;
255+
$url = sprintf('https://maps.google.com/maps/api/geocode/json?address=%s%s', $address, $keyParam);
245256

246257
$c = curl_init();
247258
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);

src/ToolboxBundle/Resources/config/pimcore/areas/googleMap.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ toolbox:
5050
scrollwheel: false
5151
map_style_url: false
5252
marker_icon: false
53-
map_api_key: '%toolbox.google_maps.browser_api_key%'
54-
simple_api_key: '%toolbox.google_maps.simple_api_key%'
53+
map_api_key: null
54+
simple_api_key: null

src/ToolboxBundle/Resources/config/services/twig.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ services:
4545
- { name: twig.extension }
4646

4747
ToolboxBundle\Twig\Extension\GoogleAPIKeysExtension:
48+
arguments:
49+
$fallbackBrowserKey: '%toolbox.google_maps.browser_api_key%'
4850
public: false
4951
autowire: true
5052
tags:

src/ToolboxBundle/Twig/Extension/GoogleAPIKeysExtension.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88

99
class GoogleAPIKeysExtension extends AbstractExtension
1010
{
11+
/**
12+
* @var string
13+
*/
14+
protected $fallbackBrowserKey;
15+
1116
/**
1217
* @var ConfigManagerInterface
1318
*/
1419
protected $configManager;
1520

1621
/**
22+
* @param string|null $fallbackBrowserKey
1723
* @param ConfigManagerInterface $configManager
1824
*/
19-
public function __construct(ConfigManagerInterface $configManager)
20-
{
25+
public function __construct(
26+
?string $fallbackBrowserKey,
27+
ConfigManagerInterface $configManager
28+
) {
29+
$this->fallbackBrowserKey = $fallbackBrowserKey;
2130
$this->configManager = $configManager;
2231
}
2332

@@ -38,11 +47,13 @@ public function getFunctions()
3847
*/
3948
public function getGoogleMapAPIKey()
4049
{
50+
$browserKey = 'please_configure_key_in_systemsettings';
4151
$configNode = $this->configManager->setAreaNameSpace(ConfigManagerInterface::AREABRICK_NAMESPACE_INTERNAL)->getAreaParameterConfig('googleMap');
4252

43-
$browserKey = 'please_configure_key_in_systemsettings';
4453
if (!empty($configNode) && isset($configNode['map_api_key']) && !empty($configNode['map_api_key'])) {
45-
$browserKey = $configNode['map_api_key'];
54+
return $configNode['map_api_key'];
55+
} elseif (!empty($this->fallbackBrowserKey)) {
56+
return $this->fallbackBrowserKey;
4657
}
4758

4859
return $browserKey;

0 commit comments

Comments
 (0)