You are here

public static function WebformLocationGeocomplete::processWebformComposite in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_location_geocomplete/src/Element/WebformLocationGeocomplete.php \Drupal\webform_location_geocomplete\Element\WebformLocationGeocomplete::processWebformComposite()

Processes a composite webform element.

Overrides WebformLocationBase::processWebformComposite

File

modules/webform_location_geocomplete/src/Element/WebformLocationGeocomplete.php, line 53

Class

WebformLocationGeocomplete
Provides a webform element for a location geocomplete element.

Namespace

Drupal\webform_location_geocomplete\Element

Code

public static function processWebformComposite(&$element, FormStateInterface $form_state, &$complete_form) {
  $element = parent::processWebformComposite($element, $form_state, $complete_form);

  // Add Google Maps API key which is required by
  // https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places
  // @see webform_location_geocomplete_js_alter()
  if (!empty($element['#api_key'])) {
    $api_key = $element['#api_key'];
  }
  else {

    /** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
    $third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
    $api_key = $third_party_settings_manager
      ->getThirdPartySetting('webform_location_geocomplete', 'default_google_maps_api_key') ?: '';
  }
  $element['#attached']['drupalSettings']['webform']['location']['geocomplete']['api_key'] = $api_key;

  // Attach library.
  $element['#attached']['library'][] = 'webform_location_geocomplete/webform_location_geocomplete.element';
  return $element;
}