summaryrefslogtreecommitdiffstats
path: root/core/modules/field/modules/email/lib/Drupal/email/Plugin/field/widget/EmailDefaultWidget.php
blob: bb4e8595ea7042a6afd601db3bf53c5a1ac170d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

/**
 * @file
 * Definition of Drupal\email\Plugin\field\widget\EmailDefaultWidget.
 */

namespace Drupal\email\Plugin\field\widget;

use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;

/**
 * Plugin implementation of the 'email_default' widget.
 *
 * @Plugin(
 *   id = "email_default",
 *   module = "email",
 *   label = @Translation("E-mail"),
 *   field_types = {
 *     "email"
 *   }
 * )
 */
class EmailDefaultWidget extends WidgetBase {

  /**
   * Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
   */
  public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
    $element['value'] = $element + array(
      '#type' => 'email',
      '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
    );
    return $element;
  }

}