You are here

protected function GeolocationField::addSelfTokens in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/field/GeolocationField.php \Drupal\geolocation\Plugin\views\field\GeolocationField::addSelfTokens()

Add any special tokens this field might use for itself.

This method is intended to be overridden by items that generate fields as a list. For example, the field that displays all terms on a node might have tokens for the tid and the term.

By convention, tokens should follow the format of {{ token__subtoken }} where token is the field ID and subtoken is the field. If the field ID is terms, then the tokens might be {{ terms__tid }} and {{ terms__name }}.

Overrides EntityField::addSelfTokens

File

src/Plugin/views/field/GeolocationField.php, line 40

Class

GeolocationField
Field handler for geolocaiton field.

Namespace

Drupal\geolocation\Plugin\views\field

Code

protected function addSelfTokens(&$tokens, $item) {
  parent::addSelfTokens($tokens, $item);
  if (empty($item['raw'])) {
    return;
  }

  /** @var \Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem $geolocationItem */
  $geolocationItem = $item['raw'];
  if ($geolocationItem
    ->isEmpty()) {
    return;
  }
  $tokens['{{ ' . $this->options['id'] . '__lat_sex }}'] = GeolocationItem::decimalToSexagesimal($geolocationItem
    ->get('lat')
    ->getValue());
  $tokens['{{ ' . $this->options['id'] . '__lng_sex }}'] = GeolocationItem::decimalToSexagesimal($geolocationItem
    ->get('lng')
    ->getValue());
}