You are here

GeolocationLatlngFormatter.php in Geolocation Field 8.2

File

src/Plugin/Field/FieldFormatter/GeolocationLatlngFormatter.php
View source
<?php

namespace Drupal\geolocation\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;

/**
 * Plugin implementation of the 'geolocation_latlng' formatter.
 *
 * @FieldFormatter(
 *   id = "geolocation_latlng",
 *   module = "geolocation",
 *   label = @Translation("Geolocation Lat/Lng"),
 *   field_types = {
 *     "geolocation"
 *   }
 * )
 */
class GeolocationLatlngFormatter extends FormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $element = [];
    foreach ($items as $delta => $item) {
      $element[$delta] = [
        '#theme' => 'geolocation_latlng_formatter',
        '#lat' => $item->lat,
        '#lng' => $item->lng,
      ];
    }
    return $element;
  }

}

Classes

Namesort descending Description
GeolocationLatlngFormatter Plugin implementation of the 'geolocation_latlng' formatter.