You are here

class KeyProvider in Geolocation Field 8.3

Class KeyProvider.

@package Drupal\geolocation

Hierarchy

Expanded class hierarchy of KeyProvider

4 files declare their use of KeyProvider
Geocodio.php in modules/geolocation_geocodio/src/Plugin/geolocation/Geocoder/Geocodio.php
GoogleGeocodingAPI.php in modules/geolocation_google_maps/src/Plugin/geolocation/Geocoder/GoogleGeocodingAPI.php
GoogleMapsProviderBase.php in modules/geolocation_google_maps/src/GoogleMapsProviderBase.php
GooglePlacesAPI.php in modules/geolocation_google_maps/modules/geolocation_google_places_api/src/Plugin/geolocation/Geocoder/GooglePlacesAPI.php

File

src/KeyProvider.php, line 10

Namespace

Drupal\geolocation
View source
class KeyProvider {

  /**
   * 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.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyProvider::getKeyValue public static function Get actual API key from key module, if possible.