3 namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\Core\Field\WidgetBase;
7 use Drupal\Core\Form\FormStateInterface;
10 * Plugin implementation of the 'uri' widget.
14 * label = @Translation("URI field"),
20 class UriWidget extends WidgetBase {
25 public static function defaultSettings() {
29 ] + parent::defaultSettings();
35 public function settingsForm(array $form, FormStateInterface $form_state) {
38 '#title' => $this->t('Size of URI field'),
39 '#default_value' => $this->getSetting('size'),
43 $element['placeholder'] = [
44 '#type' => 'textfield',
45 '#title' => $this->t('Placeholder'),
46 '#default_value' => $this->getSetting('placeholder'),
47 '#description' => $this->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.'),
55 public function settingsSummary() {
58 $summary[] = $this->t('URI field size: @size', ['@size' => $this->getSetting('size')]);
59 $placeholder = $this->getSetting('placeholder');
60 if (!empty($placeholder)) {
61 $summary[] = $this->t('Placeholder: @placeholder', ['@placeholder' => $placeholder]);
70 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
71 $element['value'] = $element + [
73 '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
74 '#size' => $this->getSetting('size'),
75 '#placeholder' => $this->getSetting('placeholder'),
76 '#maxlength' => $this->getFieldSetting('max_length'),