Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Core / Field / Plugin / Field / FieldFormatter / BasicStringFormatter.php
1 <?php
2
3 namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
4
5 use Drupal\Core\Field\FormatterBase;
6 use Drupal\Core\Field\FieldItemListInterface;
7
8 /**
9  * Plugin implementation of the 'basic_string' formatter.
10  *
11  * @FieldFormatter(
12  *   id = "basic_string",
13  *   label = @Translation("Plain text"),
14  *   field_types = {
15  *     "string_long",
16  *     "email"
17  *   },
18  *   quickedit = {
19  *     "editor" = "plain_text"
20  *   }
21  * )
22  */
23 class BasicStringFormatter extends FormatterBase {
24
25   /**
26    * {@inheritdoc}
27    */
28   public function viewElements(FieldItemListInterface $items, $langcode) {
29     $elements = [];
30
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.
34       $elements[$delta] = [
35         '#type' => 'inline_template',
36         '#template' => '{{ value|nl2br }}',
37         '#context' => ['value' => $item->value],
38       ];
39     }
40
41     return $elements;
42   }
43
44 }