public function LeafletDemoForm::buildForm in Leaflet More Maps 8
Same name and namespace in other branches
- 2.1.x leaflet_demo/src/Form/LeafletDemoForm.php \Drupal\leaflet_demo\Form\LeafletDemoForm::buildForm()
Form constructor.
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 The form structure.
Overrides FormInterface::buildForm
File
- leaflet_demo/
src/ Form/ LeafletDemoForm.php, line 76
Class
- LeafletDemoForm
- Class LeafletDemoForm.
Namespace
Drupal\leaflet_demo\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
global $base_url;
$values = $form_state
->getUserInput();
if (empty($values['latitude'])) {
$latitude = LeafletDemoForm::LEAFLET_DEMO_DEFAULT_LAT;
$longitude = LeafletDemoForm::LEAFLET_DEMO_DEFAULT_LNG;
}
else {
$latitude = $values['latitude'];
$longitude = $values['longitude'];
}
$zoom = isset($values['zoom']) ? $values['zoom'] : LeafletDemoForm::LEAFLET_DEMO_DEFAULT_ZOOM;
$form['demo_map_parameters'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Map parameters'),
'#description' => $this
->t('All maps below are centered on the same latitude, longitude and have the same initial zoom level.<br/>You may pan/drag and zoom each map individually.'),
];
$form['demo_map_parameters']['latitude'] = [
'#type' => 'textfield',
'#title' => $this
->t('Latitude'),
'#description' => $this
->t('-90 .. 90 degrees'),
'#size' => 12,
'#default_value' => $latitude,
];
$form['demo_map_parameters']['longitude'] = [
'#type' => 'textfield',
'#title' => $this
->t('Longitude'),
'#description' => $this
->t('-180 .. 180 degrees'),
'#size' => 12,
'#default_value' => $longitude,
];
$form['demo_map_parameters']['zoom'] = [
'#type' => 'textfield',
'#title' => $this
->t('Zoom'),
'#field_suffix' => $this
->t('(0..18)'),
'#description' => $this
->t('Some zoom levels may not be available in some maps.'),
'#size' => 2,
'#default_value' => $zoom,
];
$form['demo_map_parameters']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit map parameters'),
];
$form['#attached']['library'][] = 'leaflet_demo/leaflet_demo_form';
$form['demo_maps'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('All available maps'),
'#description' => '<em>' . $this
->t('If some maps do not display, this may be due to a missing or invalid map provider API key.') . '<br/>' . $this
->t('You can enter API keys <a href="@config_page">here</a>.', [
'@config_page' => $base_url . '/admin/config/system/leaflet-more-maps/',
]) . '</em>',
];
$form['demo_maps'] = array_merge($form['demo_maps'], $this
->outputDemoMaps($latitude, $longitude, $zoom));
return $form;
}