5 * Contains \Drupal\behat_test\Plugin\field\widget\AddressFieldWidget.
8 namespace Drupal\behat_test\Plugin\Field\FieldWidget;
10 use Drupal\Core\Field\FieldItemListInterface;
11 use Drupal\Core\Field\WidgetBase;
12 use Drupal\Core\Form\FormStateInterface;
15 * Plugin implementation of the 'behat_test_address_field' widget.
18 * id = "behat_test_address_field_default",
19 * label = @Translation("Address field"),
20 * module = "behat_test",
22 * "behat_test_address_field"
26 class AddressFieldWidget extends WidgetBase {
31 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
32 // Set up the form element.
33 $element += ['#type' => 'details', '#open' => TRUE];
35 // Add in the textfields.
37 'country' => t('Country'),
38 'locality' => t('Locality'),
39 'thoroughfare' => t('Thoroughfare'),
40 'postal_code' => t('Postal code'),
42 foreach ($columns as $key => $title) {
44 '#type' => 'textfield',
46 '#default_value' => isset($items[$delta]->$key) ? $items[$delta]->$key : '',