You are here

public static function WebformAddressLoqate::preRenderWebformCompositeFormElement in Loqate 8

Same name and namespace in other branches
  1. 2.x modules/pca_webform/src/Element/WebformAddressLoqate.php \Drupal\pca_webform\Element\WebformAddressLoqate::preRenderWebformCompositeFormElement()

Adds form element theming to an element if its title or description is set.

This is used as a pre render function for checkboxes and radios.

Overrides WebformCompositeFormElementTrait::preRenderWebformCompositeFormElement

File

modules/pca_webform/src/Element/WebformAddressLoqate.php, line 27

Class

WebformAddressLoqate
Provides a webform element for an address element.

Namespace

Drupal\pca_webform\Element

Code

public static function preRenderWebformCompositeFormElement($element) {
  $element = parent::preRenderWebformCompositeFormElement($element);

  // Address lookup wrapper & trigger class.
  $element['#attributes']['class'][] = 'address-lookup';
  foreach (array_keys($element['#webform_composite_elements']) as $key) {
    if ($key !== 'postal_code') {

      // Initial class for hidden fields.
      $element[$key]['#wrapper_attributes']['class'][] = 'address-lookup__field--initial';
    }

    // Generic class and data attribute.
    $element[$key]['#wrapper_attributes']['class'][] = 'address-lookup__field';
    $element[$key]['#wrapper_attributes']['data-key'] = $element['#webform_key'];
  }
  $element['#attached'] = [
    'library' => [
      'pca_webform/element.pca_webform.address.js',
    ],
    'drupalSettings' => [
      'loqate' => [
        'loqate' => [
          'key' => Loqate::getApiKey(),
        ],
      ],
    ],
  ];
  return $element;
}