You are here

private static function PcaAddressElementTrait::preparePcaOptions in Loqate 8

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

Processes additional options and overrides.

Parameters

array $element: Element array.

See also

https://www.loqate.com/resources/support/setup-guides/advanced-setup-gui...

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

File

src/PcaAddressElementTrait.php, line 189

Class

PcaAddressElementTrait
Class PcaAddressElementTrait.

Namespace

Drupal\loqate

Code

private static function preparePcaOptions(array &$element) : void {
  $element['#attached']['drupalSettings']['pca_address']['elements']['#' . $element['#id']]['options'] = [
    'key' => Loqate::getApiKey(),
  ];

  // Merge options if provided.
  if (isset($element['#pca_options'])) {

    // Before we merge the options, check on a possibly provided API key value.
    if (isset($element['#pca_options']['key']) && ($key = Loqate::getApiKey($element['#pca_options']['key']))) {

      // Replace the config key id with the key value.
      $element['#pca_options']['key'] = $key;
    }
    else {
      unset($element['#pca_options']['key']);
    }
    $element['#attached']['drupalSettings']['pca_address']['elements']['#' . $element['#id']]['options'] = array_merge($element['#attached']['drupalSettings']['pca_address']['elements']['#' . $element['#id']]['options'], $element['#pca_options']);
  }
}