You are here

GeolocationSexagesimalFormatter.php in Geolocation Field 8

File

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

namespace Drupal\geolocation\Plugin\Field\FieldFormatter;

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

/**
 * Plugin implementation of the 'geolocation_sexagesimal' formatter.
 *
 * @FieldFormatter(
 *   id = "geolocation_sexagesimal",
 *   module = "geolocation",
 *   label = @Translation("Geolocation Sexagesimal / GPS / DMS"),
 *   field_types = {
 *     "geolocation"
 *   }
 * )
 */
class GeolocationSexagesimalFormatter extends FormatterBase {

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

}

Classes

Namesort descending Description
GeolocationSexagesimalFormatter Plugin implementation of the 'geolocation_sexagesimal' formatter.