public function WebformLocationGeocomplete::form in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_location_geocomplete/src/Plugin/WebformElement/WebformLocationGeocomplete.php \Drupal\webform_location_geocomplete\Plugin\WebformElement\WebformLocationGeocomplete::form()
Gets the actual configuration webform array to be built.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array An associative array contain the element's configuration webform without any default values.
Overrides WebformLocationBase::form
File
- modules/
webform_location_geocomplete/ src/ Plugin/ WebformElement/ WebformLocationGeocomplete.php, line 109
Class
- WebformLocationGeocomplete
- Provides an 'location' element using Geocomplete.
Namespace
Drupal\webform_location_geocomplete\Plugin\WebformElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['composite']['map'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display map'),
'#description' => $this
->t('Display a map for entered location.'),
'#return_value' => TRUE,
'#states' => [
'visible' => [
':input[name="properties[hidden]"]' => [
'checked' => FALSE,
],
],
],
];
$form['composite']['api_key'] = [
'#type' => 'textfield',
'#title' => $this
->t('Google Maps API key'),
'#description' => $this
->t('Google requires users to use a valid API key. Using the <a href="https://console.developers.google.com/apis">Google API Manager</a>, you can enable the <em>Google Maps JavaScript API</em>. That will create (or reuse) a <em>Browser key</em> which you can paste here.'),
];
$default_api_key = $this->configFactory
->get('webform.settings')
->get('element.default_google_maps_api_key');
if ($default_api_key) {
$form['composite']['api_key']['#description'] .= '<br /><br />' . $this
->t('Defaults to: %value', [
'%value' => $default_api_key,
]);
}
else {
$form['composite']['api_key']['#required'] = TRUE;
if ($this->currentUser
->hasPermission('administer webform')) {
$t_args = [
':href' => UrlGenerator::fromRoute('webform.config.elements')
->toString(),
];
$form['composite']['api_key']['#description'] .= '<br /><br />' . $this
->t('You can either enter an element specific API key here or set the <a href=":href">default site-wide API key</a>.', $t_args);
}
}
return $form;
}