geolocation-8.x-3.x-dev/src/Plugin/Field/FieldFormatter/GeolocationLatlngFormatter.php

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

namespace Drupal\geolocation\Plugin\Field\FieldFormatter;

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

/**
 * Plugin implementation of the 'geolocation_latlng' formatter.
 */
#[FieldFormatter(
  id: 'geolocation_latlng',
  label: new \Drupal\Core\StringTranslation\TranslatableMarkup('Geolocation Lat/Lng'),
  field_types: ['geolocation']
)]
class GeolocationLatlngFormatter extends FormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode): array {
    $element = [];

    foreach ($items as $delta => $item) {
      $element[$delta] = [
        '#theme' => 'geolocation_latlng_formatter',
        '#lat' => $item->lat,
        '#lng' => $item->lng,
      ];
    }

    return $element;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc