function styled_google_map_build_api_url in Styled Google Map 8.2
Same name and namespace in other branches
- 8 styled_google_map.module \styled_google_map_build_api_url()
- 7.2 styled_google_map.module \styled_google_map_build_api_url()
Create url addition for Google Maps library.
Parameters
array $libraries: Any libraries that should be loaded with API.
Return value
string The url of the API for maps library.
1 call to styled_google_map_build_api_url()
- styled_google_map_library_info_alter in ./
styled_google_map.module - Implements hook_library_info_alter().
File
- ./
styled_google_map.module, line 173 - Contains all hooks and functions for the Styled Google Map module.
Code
function styled_google_map_build_api_url(array $libraries = []) {
$api_url = '';
$config = \Drupal::config('styled_google_map.settings');
switch ($config
->get('styled_google_map_google_auth_method')) {
case StyledGoogleMapInterface::STYLED_GOOGLE_MAP_GOOGLE_AUTH_KEY:
$key = $config
->get('styled_google_map_google_apikey');
if ($key) {
$query['key'] = $key;
}
break;
case StyledGoogleMapInterface::STYLED_GOOGLE_MAP_GOOGLE_AUTH_WORK:
$client_id = $config
->get('styled_google_map_google_client_id');
if ($client_id) {
$query['client'] = $client_id;
}
break;
}
$libraries = [
'visualization',
];
$additional_libraries = $config
->get('styled_google_map_libraries');
foreach ($additional_libraries as $additional_library => $enabled) {
if ($enabled) {
$libraries[] = $additional_library;
}
}
if (!empty($libraries)) {
$query['libraries'] = implode(",", $libraries);
}
// Add query params to API url.
if (!empty($query)) {
$api_url .= '?' . UrlHelper::buildQuery($query);
}
return $api_url;
}