You are here

private static function PcaAddressElementTrait::addAddressLookupField in Loqate 8

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

Adds a lookup field.

Parameters

array $element: Element array.

1 call to PcaAddressElementTrait::addAddressLookupField()
PcaAddressElementTrait::processPcaAddress in src/PcaAddressElementTrait.php
Process the PCA address form element.

File

src/PcaAddressElementTrait.php, line 87

Class

PcaAddressElementTrait
Class PcaAddressElementTrait.

Namespace

Drupal\loqate

Code

private static function addAddressLookupField(array &$element) : void {

  // Add an address lookup field.
  $element['address_lookup'] = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('Search Address'),
    '#placeholder' => new TranslatableMarkup('Start typing your address'),
    '#weight' => -90,
    '#states' => [
      'visible' => [
        'select[name="' . "{$element['#name']}[country_code]" . '"]' => [
          'filled' => TRUE,
        ],
      ],
    ],
  ];

  // Determine if we need to add a manual input link.
  if ($element['#show_address_fields'] !== TRUE && $element['#allow_manual_input'] === TRUE) {
    $manual_input_link = Link::fromTextAndUrl('Click here', Url::fromUserInput('#manual-address'));
    $element['address_lookup']['#description'] = [
      '#type' => '#markup',
      '#markup' => '<span class="manual-address">' . new TranslatableMarkup('@link to enter your address manually.', [
        '@link' => $manual_input_link
          ->toString(),
      ]) . '</span>',
    ];
  }
}