public function TextPlainFormatter::viewElements

Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().

Overrides FormatterInterface::viewElements

File

drupal/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php, line 37
Definition of Drupal\text\Plugin\field\formatter\TextPlainFormatter.

Class

TextPlainFormatter
Plugin implementation of the 'text_plain' formatter.

Namespace

Drupal\text\Plugin\field\formatter

Code

public function viewElements(EntityInterface $entity, $langcode, array $items) {
  $elements = array();
  foreach ($items as $delta => $item) {

    // The text value has no text format assigned to it, so the user input
    // should equal the output, including newlines.
    $elements[$delta] = array(
      '#markup' => nl2br(check_plain($item['value'])),
    );
  }
  return $elements;
}