You are here

protected function StringFormatter::viewValue in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::viewValue()

Generate the output appropriate for one field item.

Parameters

\Drupal\Core\Field\FieldItemInterface $item: One field item.

Return value

array The textual output generated as a render array.

1 call to StringFormatter::viewValue()
StringFormatter::viewElements in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php
Builds a renderable array for a field value.
1 method overrides StringFormatter::viewValue()
LanguageFormatter::viewValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/LanguageFormatter.php
Generate the output appropriate for one field item.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php, line 153
Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter.

Class

StringFormatter
Plugin implementation of the 'string' formatter.

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

Code

protected function viewValue(FieldItemInterface $item) {

  // The text value has no text format assigned to it, so the user input
  // should equal the output, including newlines.
  return [
    '#type' => 'inline_template',
    '#template' => '{{ value|nl2br }}',
    '#context' => [
      'value' => $item->value,
    ],
  ];
}