You are here

public function DumperPluginManager::setCountryFromGeojson in Geocoder 8.2

Same name and namespace in other branches
  1. 8.3 src/DumperPluginManager.php \Drupal\geocoder\DumperPluginManager::setCountryFromGeojson()

Define a Country value from a Geojson string.

Parameters

string $geojson: The GeoJson place string.

Return value

string A country code.

1 call to DumperPluginManager::setCountryFromGeojson()
DumperPluginManager::setAddressFieldFromGeojson in src/DumperPluginManager.php
Define an Address field value from a Geojson string.

File

src/DumperPluginManager.php, line 90

Class

DumperPluginManager
Provides a plugin manager for geocoder dumpers.

Namespace

Drupal\geocoder

Code

public function setCountryFromGeojson($geojson) {
  $geojson_array = Json::decode($geojson);
  $country_code = isset($geojson_array['properties']['countryCode']) ? strtoupper(substr($geojson_array['properties']['countryCode'], 0, 2)) : NULL;

  // Some provider (like MapQuest) might not return the countryCode but just
  // the country name, so try to convert it into countryCode, as it seems to
  // be mandatory in Address Field Entity API.
  if (!isset($country_code)) {
    $country_code = isset($geojson_array['properties']['country']) ? strtoupper(substr($geojson_array['properties']['country'], 0, 2)) : '';
  }
  return $country_code;
}