3 namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Field\FormatterBase;
6 use Drupal\Core\Field\FieldItemListInterface;
9 * Plugin implementation of the 'basic_string' formatter.
12 * id = "basic_string",
13 * label = @Translation("Plain text"),
19 * "editor" = "plain_text"
23 class BasicStringFormatter extends FormatterBase {
28 public function viewElements(FieldItemListInterface $items, $langcode) {
31 foreach ($items as $delta => $item) {
32 // The text value has no text format assigned to it, so the user input
33 // should equal the output, including newlines.
35 '#type' => 'inline_template',
36 '#template' => '{{ value|nl2br }}',
37 '#context' => ['value' => $item->value],