PlainFormatter.php 1017 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\taxonomy\Plugin\field\formatter\PlainFormatter.
 */

namespace Drupal\taxonomy\Plugin\field\formatter;

10
use Drupal\field\Annotation\FieldFormatter;
11 12
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\EntityInterface;
13
use Drupal\Core\Entity\Field\FieldInterface;
14 15 16 17 18
use Drupal\taxonomy\Plugin\field\formatter\TaxonomyFormatterBase;

/**
 * Plugin implementation of the 'taxonomy_term_reference_plain' formatter.
 *
19
 * @FieldFormatter(
20 21 22 23 24 25 26 27 28 29 30 31
 *   id = "taxonomy_term_reference_plain",
 *   label = @Translation("Plain text"),
 *   field_types = {
 *     "taxonomy_term_reference"
 *   }
 * )
 */
class PlainFormatter extends TaxonomyFormatterBase {

  /**
   * {@inheritdoc}
   */
32
  public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
33 34 35 36
    $elements = array();

    foreach ($items as $delta => $item) {
      $elements[$delta] = array(
37
        '#markup' => check_plain($item->entity->label()),
38 39 40 41 42 43 44
      );
    }

    return $elements;
  }

}