Pull merge.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / plugin / field / formatter.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Plugin\Field\FieldFormatter;
4
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\Core\Field\FormatterBase;
7 {% if configurable %}
8 use Drupal\Core\Form\FormStateInterface;
9 {% endif %}
10
11 /**
12  * Plugin implementation of the '{{ plugin_label }}' formatter.
13  *
14  * @FieldFormatter(
15  *   id = "{{ plugin_id }}",
16  *   label = @Translation("{{ plugin_label }}"),
17  *   field_types = {
18  *     "string"
19  *   }
20  * )
21  */
22 class {{ class }} extends FormatterBase {
23
24 {% if configurable %}
25   /**
26    * {@inheritdoc}
27    */
28   public static function defaultSettings() {
29     return [
30       'foo' => 'bar',
31     ] + parent::defaultSettings();
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function settingsForm(array $form, FormStateInterface $form_state) {
38
39     $elements['foo'] = [
40       '#type' => 'textfield',
41       '#title' => $this->t('Foo'),
42       '#default_value' => $this->getSetting('foo'),
43     ];
44
45     return $elements;
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function settingsSummary() {
52     $summary[] = $this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]);
53     return $summary;
54   }
55
56 {% endif %}
57   /**
58    * {@inheritdoc}
59    */
60   public function viewElements(FieldItemListInterface $items, $langcode) {
61     $element = [];
62
63     foreach ($items as $delta => $item) {
64       $element[$delta] = [
65         '#type' => 'item',
66         '#markup' => $item->value,
67       ];
68     }
69
70     return $element;
71   }
72
73 }