Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-extension / fixtures / drupal8 / modules / behat_test / src / Plugin / Field / FieldWidget / AddressFieldWidget.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\behat_test\Plugin\field\widget\AddressFieldWidget.
6  */
7
8 namespace Drupal\behat_test\Plugin\Field\FieldWidget;
9
10 use Drupal\Core\Field\FieldItemListInterface;
11 use Drupal\Core\Field\WidgetBase;
12 use Drupal\Core\Form\FormStateInterface;
13
14 /**
15  * Plugin implementation of the 'behat_test_address_field' widget.
16  *
17  * @FieldWidget(
18  *   id = "behat_test_address_field_default",
19  *   label = @Translation("Address field"),
20  *   module = "behat_test",
21  *   field_types = {
22  *     "behat_test_address_field"
23  *   }
24  * )
25  */
26 class AddressFieldWidget extends WidgetBase {
27
28   /**
29    * {@inheritdoc}
30    */
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];
34
35     // Add in the textfields.
36     $columns = [
37       'country' => t('Country'),
38       'locality' => t('Locality'),
39       'thoroughfare' => t('Thoroughfare'),
40       'postal_code' => t('Postal code'),
41     ];
42     foreach ($columns as $key => $title) {
43       $element[$key] = [
44         '#type' => 'textfield',
45         '#title' => $title,
46         '#default_value' => isset($items[$delta]->$key) ? $items[$delta]->$key : '',
47       ];
48     }
49
50     return $element;
51   }
52
53 }