OptionsKeyFormatter.php

Contains \Drupal\options\Plugin\field\formatter\OptionsKeyFormatter.

Namespace

Drupal\options\Plugin\field\formatter

File

drupal/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsKeyFormatter.php
View source
<?php

/**
 * @file
 * Contains \Drupal\options\Plugin\field\formatter\OptionsKeyFormatter.
 */
namespace Drupal\options\Plugin\field\formatter;

use Drupal\field\Annotation\FieldFormatter;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
use Drupal\Core\Entity\EntityInterface;

/**
 * Plugin implementation of the 'list_key' formatter.
 *
 * @FieldFormatter(
 *   id = "list_key",
 *   module = "options",
 *   label = @Translation("Key"),
 *   field_types = {
 *     "list_integer",
 *     "list_float",
 *     "list_text",
 *     "list_boolean"
 *   }
 * )
 */
class OptionsKeyFormatter extends FormatterBase {

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

}

Classes

Namesort descending Description
OptionsKeyFormatter Plugin implementation of the 'list_key' formatter.