You are here

public function GeolocationComputed::getValue in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/TypedData/GeolocationComputed.php \Drupal\geolocation\TypedData\GeolocationComputed::getValue()

Gets the data value.

Return value

mixed The data value.

Overrides TypedData::getValue

File

src/TypedData/GeolocationComputed.php, line 27

Class

GeolocationComputed
Class GeolocationComputed.

Namespace

Drupal\geolocation\TypedData

Code

public function getValue() {
  if ($this->value !== NULL) {
    return $this->value;
  }

  /** @var \Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem $item */
  $item = $this
    ->getParent();
  if ($item) {
    $lat = trim($item
      ->get('lat')
      ->getValue());
    $lng = trim($item
      ->get('lng')
      ->getValue());

    // Ensure latitude and longitude exist.
    if ($lat !== NULL && $lng !== NULL) {

      // Format the returned value.
      $this->value = $lat . ', ' . $lng;
    }
  }
  return $this->value;
}