You are here

public function IpGeoLocViewsPluginStyle::pluginStyleGetBase2 in IP Geolocation Views & Maps 8

Plugin style base.

1 call to IpGeoLocViewsPluginStyle::pluginStyleGetBase2()
IpGeoLocViewsPluginStyle::pluginStyleExtractLatLng in src/Services/IpGeoLocViewsPluginStyle.php
Extract coordinates from the View result row.

File

src/Services/IpGeoLocViewsPluginStyle.php, line 803

Class

IpGeoLocViewsPluginStyle
Class IpGeoLocViewsPluginStyle.

Namespace

Drupal\ip_geoloc\Services

Code

public function pluginStyleGetBase2($row, $field_name, $delta) {
  if (!isset($row) || !isset($field_name) || !isset($delta)) {
    return NULL;
  }
  $field = $row
    ->get($field_name);
  $field_value = $field
    ->getValue();
  if (!$row
    ->get($field_name)
    ->isEmpty() && is_array($field_value)) {
    if (!empty($field_value[$delta])) {
      return $field_value[$delta];

      // Geofield     : field_<field_name>[0]['raw']['geom']
      // Geolocation  : field_<field_name>[0]['raw']['lat'] and ...]['lng']
      // Get Locations: field_<field_name>[0]['raw']['latitude'].
    }

    // $lang = Language::LANGCODE_NOT_SPECIFIED;.
    // @TODO Check the translation implementation
    $lang = \Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();
    if ($translated_entity = $row
      ->getTranslation($lang)) {

      // EntityFieldQuery Views Backend.
      // For Geofield module lat/long are as follows (note: no extra
      // 'field_' prefix):
      // <field_name>['und]['0']['wkt'], for example:
      // POINT (144.976 -37.813) or MULTIPOINT ( (),(),() )
      $field_value = $translated_entity
        ->getValue();
      return $field_value[$delta];
    }

    // This doesnt apply for d8
    // Last resort, retrieve from rendered, as opposed to raw, result.

    /*if (!empty($row->{$field_name}[$delta]['rendered'])) {
      $base = $row->{$field_name}[$delta]['rendered'];
      return empty($base['#markup']) ? $base : $base['#markup'];
      }*/
  }
  return NULL;
}