You are here

function styled_google_map_build_api_url in Styled Google Map 8

Same name and namespace in other branches
  1. 8.2 styled_google_map.module \styled_google_map_build_api_url()
  2. 7.2 styled_google_map.module \styled_google_map_build_api_url()

Create url addition for Google Maps library.

Return value

string Url for the google maps library with API key.

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 177
Contains all hooks and functions for the Styled Google Map module.

Code

function styled_google_map_build_api_url() {
  $api_url = '';
  $config = \Drupal::config('styled_google_map.settings');
  $query = array(
    'v' => '3',
  );
  switch ($config
    ->get('styled_google_map_google_auth_method')) {
    case STYLED_GOOGLE_MAP_GOOGLE_AUTH_KEY:
      $key = $config
        ->get('styled_google_map_google_apikey', FALSE);
      if ($key) {
        $query['key'] = $key;
      }
      break;
    case STYLED_GOOGLE_MAP_GOOGLE_AUTH_WORK:
      $client_id = $config
        ->get('styled_google_map_google_client_id', FALSE);
      if ($client_id) {
        $query['client'] = $client_id;
      }
      break;
  }

  // Add query params to API url.
  if (!empty($query)) {
    $api_url .= '?' . UrlHelper::buildQuery($query);
  }
  return $api_url;
}