3 namespace Drupal\{{ machine_name }}\Plugin\Field\FieldWidget;
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\Core\Field\WidgetBase;
7 use Drupal\Core\Form\FormStateInterface;
10 * Defines the '{{ plugin_id }}' field widget.
13 * id = "{{ plugin_id }}",
14 * label = @Translation("{{ plugin_label }}"),
15 * field_types = {"string"},
18 class {{ class }} extends WidgetBase {
24 public static function defaultSettings() {
27 ] + parent::defaultSettings();
33 public function settingsForm(array $form, FormStateInterface $form_state) {
36 '#type' => 'textfield',
37 '#title' => $this->t('Foo'),
38 '#default_value' => $this->getSetting('foo'),
47 public function settingsSummary() {
48 $summary[] = $this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]);
56 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
58 $element['value'] = $element + [
59 '#type' => 'textfield',
60 '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,