You are here

public static function KeyProvider::getKeyValue in Geolocation Field 8.3

Get actual API key from key module, if possible.

So that we don't need to store plain text api key secrets in config file.

5 calls to KeyProvider::getKeyValue()
Geocodio::geocode in modules/geolocation_geocodio/src/Plugin/geolocation/Geocoder/Geocodio.php
Geocode an address.
GoogleGeocodingAPI::geocode in modules/geolocation_google_maps/src/Plugin/geolocation/Geocoder/GoogleGeocodingAPI.php
Geocode an address.
GoogleGeocodingAPI::reverseGeocode in modules/geolocation_google_maps/src/Plugin/geolocation/Geocoder/GoogleGeocodingAPI.php
Reverse geocode an address.
GoogleMapsProviderBase::getGoogleMapsApiParameters in modules/geolocation_google_maps/src/GoogleMapsProviderBase.php
Return all module and custom defined parameters.
GooglePlacesAPI::geocode in modules/geolocation_google_maps/modules/geolocation_google_places_api/src/Plugin/geolocation/Geocoder/GooglePlacesAPI.php
Geocode an address.

File

src/KeyProvider.php, line 17

Class

KeyProvider
Class KeyProvider.

Namespace

Drupal\geolocation

Code

public static function getKeyValue($api_key) {
  if (empty($api_key)) {
    return $api_key;
  }

  // If the "Key" module exists, assume we are storing the key name instead of
  // the actual value, which should be a secret not saved in config.
  if (!\Drupal::moduleHandler()
    ->moduleExists('key')) {
    return $api_key;
  }
  $store = \Drupal::service('key.repository')
    ->getKey($api_key);
  if (empty($store)) {
    return $api_key;
  }
  $store_key = $store
    ->getKeyValue();
  if (empty($store_key)) {
    return $api_key;
  }
  return $store_key;
}