You are here

public function LocationManager::getLocation in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/LocationManager.php \Drupal\geolocation\LocationManager::getLocation()

Get location center coordinates.

Parameters

array $settings: Center option settings.

mixed $context: Context.

Return value

array Centre value.

File

src/LocationManager.php, line 166

Class

LocationManager
Search plugin manager.

Namespace

Drupal\geolocation

Code

public function getLocation(array $settings, $context = NULL) {
  $center = [];
  foreach ($settings as $option_id => $option) {

    // Ignore if not enabled.
    if (empty($option['enable'])) {
      continue;
    }
    if (!$this
      ->hasDefinition($option['location_plugin_id'])) {
      continue;
    }

    /** @var \Drupal\geolocation\LocationInterface $location_plugin */
    $location_plugin = $this
      ->createInstance($option['location_plugin_id']);
    $plugin_center = $location_plugin
      ->getCoordinates($option_id, empty($option['settings']) ? [] : $option['settings'], $context);
    if (!empty($plugin_center)) {

      // Break on first found center.
      return $plugin_center;
    }
  }
  return $center;
}