geolocation-8.x-3.x-dev/modules/geolocation_geometry/src/Plugin/views/field/GeoProximityField.php
modules/geolocation_geometry/src/Plugin/views/field/GeoProximityField.php
<?php
namespace Drupal\geolocation_geometry\Plugin\views\field;
use Drupal\views\Attribute\ViewsField;
use Drupal\geolocation\Plugin\views\field\ProximityField;
use Drupal\geolocation_geometry\GeometryProximityTrait;
/**
* Field handler for geolocation field.
*
* @ingroup views_field_handlers
*/
#[ViewsField(id: 'geolocation_geometry_field_proximity')]
class GeoProximityField extends ProximityField {
use GeometryProximityTrait;
/**
* {@inheritdoc}
*/
public function query(): void {
/** @var \Drupal\views\Plugin\views\query\Sql $query */
$query = $this->query;
$center = $this->getCenter();
if (empty($center)) {
return;
}
// Build the query expression.
$expression = self::getGeometryProximityQueryFragment($this->ensureMyTable(), $this->realField, $center['lat'], $center['lng']);
// Get a placeholder for this query and save the field_alias for it.
// Remove the initial ':' from the placeholder and avoid collision with
// the original field name.
// @phpstan-ignore-next-line
$this->field_alias = $query->addField(NULL, $expression, substr($this->placeholder(), 1));
}
}
