Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / templates / module / src / Plugin / Field / FieldFormatter / fieldformatter.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{ module }}\Plugin\Field\FieldFormatter\{{ class_name }}.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{ module }}\Plugin\Field\FieldFormatter;
9 {% endblock %}
10
11 {% block use_class %}
12 use Drupal\Component\Utility\Html;
13 use Drupal\Core\Field\FieldItemInterface;
14 use Drupal\Core\Field\FieldItemListInterface;
15 use Drupal\Core\Field\FormatterBase;
16 use Drupal\Core\Form\FormStateInterface;
17 {% endblock %}
18
19 {% block class_declaration %}
20 /**
21  * Plugin implementation of the '{{ plugin_id }}' formatter.
22  *
23  * @FieldFormatter(
24  *   id = "{{ plugin_id }}",
25  *   label = @Translation("{{ label }}"){% if field_type %},
26  *   field_types = {
27  *     "{{ field_type }}"
28  *   }
29 {% else %}
30
31  *   At least one field_types annotation array entry is necessary to display this formatter in the UI.
32  *   ex. field_types = { "field_type" }
33 {% endif %}
34  * )
35  */
36 class {{ class_name }} extends FormatterBase {% endblock %}
37 {% block class_methods %}
38   /**
39    * {@inheritdoc}
40    */
41   public static function defaultSettings() {
42     return [
43       // Implement default settings.
44     ] + parent::defaultSettings();
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function settingsForm(array $form, FormStateInterface $form_state) {
51     return [
52       // Implement settings form.
53     ] + parent::settingsForm($form, $form_state);
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function settingsSummary() {
60     $summary = [];
61     // Implement settings summary.
62
63     return $summary;
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function viewElements(FieldItemListInterface $items, $langcode) {
70     $elements = [];
71
72     foreach ($items as $delta => $item) {
73       $elements[$delta] = ['#markup' => $this->viewValue($item)];
74     }
75
76     return $elements;
77   }
78
79   /**
80    * Generate the output appropriate for one field item.
81    *
82    * @param \Drupal\Core\Field\FieldItemInterface $item
83    *   One field item.
84    *
85    * @return string
86    *   The textual output generated.
87    */
88   protected function viewValue(FieldItemInterface $item) {
89     // The text value has no text format assigned to it, so the user input
90     // should equal the output, including newlines.
91     return nl2br(Html::escape($item->value));
92   }
93 {% endblock %}