WebformLocationPlaces.php in Webform 6.x
File
src/Element/WebformLocationPlaces.php
View source
<?php
namespace Drupal\webform\Element;
use Drupal\Core\Form\FormStateInterface;
class WebformLocationPlaces extends WebformLocationBase {
protected static $name = 'places';
public function getInfo() {
return parent::getInfo() + [
'#app_id' => '',
'#api_key' => '',
];
}
public static function getLocationAttributes() {
return [
'lat' => t('Latitude'),
'lng' => t('Longitude'),
'name' => t('Name'),
'city' => t('City'),
'country' => t('Country'),
'country_code' => t('Country Code'),
'administrative' => t('State/Province'),
'county' => t('County'),
'suburb' => t('Suburb'),
'postcode' => t('Postal Code'),
];
}
public static function processWebformComposite(&$element, FormStateInterface $form_state, &$complete_form) {
$element = parent::processWebformComposite($element, $form_state, $complete_form);
$app_id = !empty($element['#app_id']) ? $element['#app_id'] : \Drupal::config('webform.settings')
->get('element.default_algolia_places_app_id');
$api_key = !empty($element['#api_key']) ? $element['#api_key'] : \Drupal::config('webform.settings')
->get('element.default_algolia_places_api_key');
$element['#attached']['drupalSettings']['webform']['location']['places'] = [
'app_id' => $app_id,
'api_key' => $api_key,
];
$element['#attached']['library'][] = 'webform/webform.element.location.places';
return $element;
}
}