You are here

private static function PcaAddressElementTrait::addAddressLabelField in Loqate 8

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

Adds a address label field.

Parameters

array $element: Element array.

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

File

src/PcaAddressElementTrait.php, line 118

Class

PcaAddressElementTrait
Class PcaAddressElementTrait.

Namespace

Drupal\loqate

Code

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

  // Do not process a field label if we show address fields initially as that
  // is redundant to display to the end user.
  if ($element['#show_address_fields'] === TRUE) {
    return;
  }

  // Add an address label field for plain text details.
  $element['address_label'] = [
    '#type' => 'fieldset',
    '#title' => new TranslatableMarkup('Address'),
    '#markup' => '<span class="address-label"></span>',
    '#weight' => -80,
    '#attributes' => [
      'class' => [
        'address-label-wrapper',
        'hidden',
      ],
    ],
  ];

  // Determine if we need to add an edit address link.
  if ($element['#allow_manual_input'] === TRUE) {
    $edit_input_link = Link::fromTextAndUrl('Edit address', Url::fromUserInput('#edit-address'));
    $element['address_label']['#markup'] .= '<span class="edit-address">' . $edit_input_link
      ->toString() . '</span>';
  }
}