You are here

public function GeolocationItem::setValue in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldType/GeolocationItem.php \Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem::setValue()
  2. 8 src/Plugin/Field/FieldType/GeolocationItem.php \Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem::setValue()

Overrides \Drupal\Core\TypedData\TypedData::setValue().

Parameters

array|null $values: An array of property values.

Overrides FieldItemBase::setValue

File

src/Plugin/Field/FieldType/GeolocationItem.php, line 152

Class

GeolocationItem
Plugin implementation of the 'geolocation' field type.

Namespace

Drupal\geolocation\Plugin\Field\FieldType

Code

public function setValue($values, $notify = TRUE) {
  parent::setValue($values, $notify);

  // If the values being set do not contain lat_sin, lat_cos or lng_rad,
  // recalculate them.
  if ((empty($values['lat_sin']) || empty($values['lat_cos']) || empty($values['lat_rad'])) && !$this
    ->isEmpty()) {
    $this
      ->get('lat_sin')
      ->setValue(sin(deg2rad(trim($this
      ->get('lat')
      ->getValue()))), FALSE);
    $this
      ->get('lat_cos')
      ->setValue(cos(deg2rad(trim($this
      ->get('lat')
      ->getValue()))), FALSE);
    $this
      ->get('lng_rad')
      ->setValue(deg2rad(trim($this
      ->get('lng')
      ->getValue())), FALSE);
  }
}