You are here

public static function LoqatePcaAddress::processAddress in Loqate 8

Same name and namespace in other branches
  1. 2.x src/Element/LoqatePcaAddress.php \Drupal\loqate\Element\LoqatePcaAddress::processAddress()

Process the address fields.

File

src/Element/LoqatePcaAddress.php, line 70

Class

LoqatePcaAddress
Provides a standalone Loqate PCA address form element.

Namespace

Drupal\loqate\Element

Code

public static function processAddress(array &$element, FormStateInterface $form_state, array &$complete_form) {

  // Ensure tree structure in output.
  $element['#tree'] = TRUE;
  $element[PcaAddressElement::LINE1] = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('Address Line 1'),
    '#default_value' => $element['#default_value'][PcaAddressElement::LINE1] ?? NULL,
    '#required' => TRUE,
  ];
  $element[PcaAddressElement::LINE2] = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('Address Line 2'),
    '#default_value' => $element['#default_value'][PcaAddressElement::LINE2] ?? NULL,
  ];
  $element[PcaAddressElement::POSTAL_CODE] = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('ZIP/Postal Code'),
    '#default_value' => $element['#default_value'][PcaAddressElement::POSTAL_CODE] ?? NULL,
    '#required' => TRUE,
    '#size' => 10,
  ];
  $element[PcaAddressElement::LOCALITY] = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('City/Town'),
    '#default_value' => $element['#default_value'][PcaAddressElement::LOCALITY] ?? NULL,
    '#required' => TRUE,
    '#size' => 30,
  ];
  $element[PcaAddressElement::ADMINISTRATIVE_AREA] = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('State/Province'),
    '#default_value' => $element['#default_value'][PcaAddressElement::ADMINISTRATIVE_AREA] ?? NULL,
    '#size' => 30,
  ];
  $element[PcaAddressElement::COUNTRY_CODE] = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('Country'),
    '#default_value' => $element['#default_value'][PcaAddressElement::COUNTRY_CODE] ?? NULL,
  ];
  return $element;
}