function TextDefaultFormatter::viewElements

Same name in other branches
  1. 9 core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php \Drupal\text\Plugin\Field\FieldFormatter\TextDefaultFormatter::viewElements()
  2. 10 core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php \Drupal\text\Plugin\Field\FieldFormatter\TextDefaultFormatter::viewElements()
  3. 11.x core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php \Drupal\text\Plugin\Field\FieldFormatter\TextDefaultFormatter::viewElements()

Overrides FormatterInterface::viewElements

File

core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php, line 26

Class

TextDefaultFormatter
Plugin implementation of the 'text_default' formatter.

Namespace

Drupal\text\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    // The ProcessedText element already handles cache context & tag bubbling.
    // @see \Drupal\filter\Element\ProcessedText::preRenderText()
    foreach ($items as $delta => $item) {
        $elements[$delta] = [
            '#type' => 'processed_text',
            '#text' => $item->value,
            '#format' => $item->format,
            '#langcode' => $item->getLangcode(),
        ];
    }
    return $elements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.