You are here

public function EntityArgument::getParsedReferenceLocation in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/views/argument/EntityArgument.php \Drupal\geolocation\Plugin\views\argument\EntityArgument::getParsedReferenceLocation()

Processes the passed argument into an array of relevant geolocation data.

Return value

array|bool The calculated values.

Overrides ProximityArgument::getParsedReferenceLocation

File

src/Plugin/views/argument/EntityArgument.php, line 165

Class

EntityArgument
Argument handler for geolocation.

Namespace

Drupal\geolocation\Plugin\views\argument

Code

public function getParsedReferenceLocation() {

  // Cache the vales so this only gets processed once.
  static $values;
  if (!isset($values)) {
    preg_match('/^([0-9]+)([<>=]+)([0-9.]+)(.*$)/', $this
      ->getValue(), $values);
    if (empty($values) && !empty($this
      ->getValue()) && is_numeric($this
      ->getValue())) {
      $values = $this
        ->getCoordinatesFromEntityId($this
        ->getValue());
      return $values;
    }
    elseif (empty($values)) {
      return [];
    }
    else {
      $values = is_array($values) ? [
        'id' => isset($values[1]) && is_numeric($values[1]) ? intval($values[1]) : FALSE,
        'operator' => isset($values[2]) && in_array($values[2], [
          '<>',
          '=',
          '>=',
          '<=',
          '>',
          '<',
        ]) ? $values[2] : '<=',
        'distance' => isset($values[3]) ? floatval($values[3]) : FALSE,
        'unit' => !empty($values[4]) ? $values[4] : 'km',
      ] : FALSE;
    }
    $coordinates = $this
      ->getCoordinatesFromEntityId($values['id']);
    if (empty($coordinates)) {
      return [];
    }
    $values = array_replace($values, $coordinates);
  }
  return $values;
}