You are here

public function GeocoderManager::getGeocoder in Geolocation Field 8

Same name and namespace in other branches
  1. 8.3 src/GeocoderManager.php \Drupal\geolocation\GeocoderManager::getGeocoder()
  2. 8.2 src/GeocoderManager.php \Drupal\geolocation\GeocoderManager::getGeocoder()

Return Geocoder by ID.

Parameters

string $id: Geocoder ID.

array $configuration: Configuration.

Return value

\Drupal\geolocation\GeocoderInterface|false Geocoder instance.

File

src/GeocoderManager.php, line 43

Class

GeocoderManager
Search plugin manager.

Namespace

Drupal\geolocation

Code

public function getGeocoder($id, array $configuration = []) {
  $definitions = $this
    ->getDefinitions();
  if (empty($definitions[$id])) {
    return FALSE;
  }
  try {

    /** @var \Drupal\geolocation\GeocoderInterface $instance */
    $instance = $this
      ->createInstance($id, $configuration);
    if ($instance) {
      return $instance;
    }
  } catch (\Exception $e) {
    return FALSE;
  }
  return FALSE;
}