TextDefaultFormatter.php

Same filename and directory in other branches
  1. 9 core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php
  2. 8.9.x core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php
  3. 10 core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php

Namespace

Drupal\text\Plugin\Field\FieldFormatter

File

core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php

View source
<?php

namespace Drupal\text\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Plugin implementation of the 'text_default' formatter.
 */
class TextDefaultFormatter extends FormatterBase {
  
  /**
   * {@inheritdoc}
   */
  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;
  }

}

Classes

Title Deprecated Summary
TextDefaultFormatter Plugin implementation of the 'text_default' formatter.

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