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

/**
 * @file
 * Definition of Drupal\text\Plugin\field\formatter\TextDefaultFormatter.
 */

namespace Drupal\text\Plugin\field\formatter;

10
use Drupal\field\Annotation\FieldFormatter;
11 12 13
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
use Drupal\Core\Entity\EntityInterface;
14
use Drupal\Core\Entity\Field\FieldInterface;
15 16 17 18

/**
 * Plugin implementation of the 'text_default' formatter.
 *
19
 * @FieldFormatter(
20 21 22 23 24 25
 *   id = "text_default",
 *   label = @Translation("Default"),
 *   field_types = {
 *     "text",
 *     "text_long",
 *     "text_with_summary"
26 27 28
 *   },
 *   edit = {
 *     "editor" = "direct"
29 30 31 32 33 34
 *   }
 * )
 */
class TextDefaultFormatter extends FormatterBase {

  /**
35
   * {@inheritdoc}
36
   */
37
  public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
38 39 40
    $elements = array();

    foreach ($items as $delta => $item) {
41
      $elements[$delta] = array('#markup' => $item->processed);
42 43 44 45 46 47
    }

    return $elements;
  }

}