
| Current Path : /var/www/html/vendor/chi-teck/drupal-code-generator/templates/plugin/field/widget/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/vendor/chi-teck/drupal-code-generator/templates/plugin/field/widget/widget.twig |
<?php
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Defines the '{{ plugin_id }}' field widget.
*
* @FieldWidget(
* id = "{{ plugin_id }}",
* label = @Translation("{{ plugin_label }}"),
* field_types = {"string"},
* )
*/
class {{ class }} extends WidgetBase {
{% if configurable %}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'foo' => 'bar',
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['foo'] = [
'#type' => 'textfield',
'#title' => $this->t('Foo'),
'#default_value' => $this->getSetting('foo'),
];
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary[] = $this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]);
return $summary;
}
{% endif %}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['value'] = $element + [
'#type' => 'textfield',
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
];
return $element;
}
}