Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / templates / module / src / Plugin / Field / FieldWidget / fieldwidget.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{ module }}\Plugin\Field\FieldWidget\{{ class_name }}.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{ module }}\Plugin\Field\FieldWidget;
9 {% endblock %}
10
11 {% block use_class %}
12 use Drupal\Core\Field\FieldItemListInterface;
13 use Drupal\Core\Field\WidgetBase;
14 use Drupal\Core\Form\FormStateInterface;
15 {% endblock %}
16
17 {% block class_declaration %}
18 /**
19  * Plugin implementation of the '{{ plugin_id }}' widget.
20  *
21  * @FieldWidget(
22  *   id = "{{ plugin_id }}",
23  *   label = @Translation("{{ label }}"){% if field_type %},
24  *   field_types = {
25  *     "{{ field_type }}"
26  *   }
27 {% else %}
28
29  *   At least one field_types annotation array entry is necessary to display this formatter in the UI.
30  *   ex. field_types = { "field_type" }
31 {% endif %}
32  * )
33  */
34 class {{ class_name }} extends WidgetBase {% endblock %}
35 {% block class_methods %}
36   /**
37    * {@inheritdoc}
38    */
39   public static function defaultSettings() {
40     return [
41       'size' => 60,
42       'placeholder' => '',
43     ] + parent::defaultSettings();
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function settingsForm(array $form, FormStateInterface $form_state) {
50     $elements = [];
51
52     $elements['size'] = [
53       '#type' => 'number',
54       '#title' => t('Size of textfield'),
55       '#default_value' => $this->getSetting('size'),
56       '#required' => TRUE,
57       '#min' => 1,
58     ];
59     $elements['placeholder'] = [
60       '#type' => 'textfield',
61       '#title' => t('Placeholder'),
62       '#default_value' => $this->getSetting('placeholder'),
63       '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
64     ];
65
66     return $elements;
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function settingsSummary() {
73     $summary = [];
74
75     $summary[] = t('Textfield size: @size', ['@size' => $this->getSetting('size')]);
76     if (!empty($this->getSetting('placeholder'))) {
77       $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $this->getSetting('placeholder')]);
78     }
79
80     return $summary;
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
87     $element['value'] = $element + [
88       '#type' => 'textfield',
89       '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
90       '#size' => $this->getSetting('size'),
91       '#placeholder' => $this->getSetting('placeholder'),
92       '#maxlength' => $this->getFieldSetting('max_length'),
93     ];
94
95     return $element;
96   }
97 {% endblock %}