public function SearchAPI::getPositionsFromViewsRow in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_search_api/src/Plugin/geolocation/DataProvider/SearchAPI.php \Drupal\geolocation_search_api\Plugin\geolocation\DataProvider\SearchAPI::getPositionsFromViewsRow()
Get positions from views row.
Parameters
\Drupal\views\ResultRow $row: Row.
\Drupal\views\Plugin\views\field\FieldPluginBase $views_field: Views field definition.
Return value
array Retrieved locations.
Overrides DataProviderBase::getPositionsFromViewsRow
File
- modules/
geolocation_search_api/ src/ Plugin/ geolocation/ DataProvider/ SearchAPI.php, line 58
Class
- SearchAPI
- Provides Google Maps.
Namespace
Drupal\geolocation_search_api\Plugin\geolocation\DataProviderCode
public function getPositionsFromViewsRow(ResultRow $row, FieldPluginBase $views_field = NULL) {
$positions = [];
if (!$views_field instanceof SearchApiEntityField) {
return [];
}
foreach ($views_field
->getItems($row) as $item) {
if (!empty($item['value'])) {
$pieces = explode(',', $item['value']);
if (count($pieces) != 2) {
continue;
}
$positions[] = [
'lat' => $pieces[0],
'lng' => $pieces[1],
];
}
elseif (!empty($item['raw'])) {
/** @var \Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem $geolocation_item */
$geolocation_item = $item['raw'];
$positions[] = [
'lat' => $geolocation_item
->get('lat')
->getValue(),
'lng' => $geolocation_item
->get('lng')
->getValue(),
];
}
}
return $positions;
}