You are here

CountryCodeFormatter.php in Country 8

File

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

namespace Drupal\country\Plugin\Field\FieldFormatter;

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

/**
 * Plugin implementation of the 'country' formatter showing the iso code.
 *
 * @FieldFormatter(
 *   id = "country_iso_code",
 *   module = "country",
 *   label = @Translation("ISO code"),
 *   field_types = {
 *     "country"
 *   }
 * )
 */
class CountryCodeFormatter extends FormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
      $elements[$delta] = [
        '#markup' => $item->value,
      ];
    }
    return $elements;
  }

}

Classes

Namesort descending Description
CountryCodeFormatter Plugin implementation of the 'country' formatter showing the iso code.