ViewsEntityArgument.php in Geolocation Field 8.3
File
src/Plugin/geolocation/Location/ViewsEntityArgument.php
View source
<?php
namespace Drupal\geolocation\Plugin\geolocation\Location;
use Drupal\geolocation\LocationInterface;
use Drupal\geolocation\LocationBase;
use Drupal\geolocation\ViewsContextTrait;
class ViewsEntityArgument extends LocationBase implements LocationInterface {
use ViewsContextTrait;
public function getAvailableLocationOptions($context) {
$options = [];
if ($displayHandler = self::getViewsDisplayHandler($context)) {
foreach ($displayHandler
->getHandlers('argument') as $argument_id => $argument) {
if ($argument
->getPluginId() == 'geolocation_entity_argument') {
$options[$argument_id] = $this
->t('Entity argument') . ' - ' . $argument
->adminLabel();
}
}
}
return $options;
}
public function getCoordinates($location_option_id, array $location_option_settings, $context = NULL) {
if (!($displayHandler = self::getViewsDisplayHandler($context))) {
return parent::getCoordinates($location_option_id, $location_option_settings, $context);
}
$handler = $displayHandler
->getHandler('argument', $location_option_id);
if (empty($handler)) {
return FALSE;
}
if ($values = $handler
->getParsedReferenceLocation()) {
if (isset($values['lat']) && isset($values['lng'])) {
return [
'lat' => $values['lat'],
'lng' => $values['lng'],
];
}
}
return parent::getCoordinates($location_option_id, $location_option_settings, $context);
}
}