public function LeafletDefaultWidget::settingsForm in Leaflet 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldWidget/LeafletDefaultWidget.php \Drupal\leaflet\Plugin\Field\FieldWidget\LeafletDefaultWidget::settingsForm()
- 2.1.x src/Plugin/Field/FieldWidget/LeafletDefaultWidget.php \Drupal\leaflet\Plugin\Field\FieldWidget\LeafletDefaultWidget::settingsForm()
File
- src/
Plugin/ Field/ FieldWidget/ LeafletDefaultWidget.php, line 187
Class
- LeafletDefaultWidget
- Plugin implementation of the "leaflet_widget" widget.
Namespace
Drupal\leaflet\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$map_settings = $this
->getSetting('map');
$default_settings = self::defaultSettings();
$form['map'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Map Settings'),
];
$form['map']['leaflet_map'] = [
'#title' => $this
->t('Leaflet Map'),
'#type' => 'select',
'#options' => [
'' => $this
->t('-- Empty --'),
] + $this
->getLeafletMaps(),
'#default_value' => $map_settings['leaflet_map'] ?? $default_settings['map']['leaflet_map'],
'#required' => TRUE,
];
$form['map']['height'] = [
'#title' => $this
->t('Height'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $map_settings['height'] ?? $default_settings['map']['height'],
];
$form['map']['auto_center'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically center map on existing features'),
'#description' => t("This option overrides the widget's default center."),
'#default_value' => $map_settings['auto_center'] ?? $default_settings['map']['auto_center'],
];
// Generate the Leaflet Map Position Form Element.
$map_position_options = $map_settings['map_position'] ?? $default_settings['map']['map_position'];
$form['map']['map_position'] = $this
->generateMapPositionElement($map_position_options);
$form['map']['locate'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically locate user current position'),
'#description' => t("This option centers the map to the user position."),
'#default_value' => $map_settings['locate'] ?? $default_settings['map']['locate'],
];
$form['map']['scroll_zoom_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Scroll Wheel Zoom on click'),
'#description' => t("This option enables zooming by mousewheel as soon as the user clicked on the map."),
'#default_value' => $map_settings['scroll_zoom_enabled'] ?? $default_settings['map']['scroll_zoom_enabled'],
];
$form['map']['fullscreen_control'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Fullscreen Control'),
'#description' => $this
->t('Enable the Fullscreen View of the Map.'),
'#default_value' => $map_settings['fullscreen_control'] ?? $default_settings['map']['fullscreen_control'],
'#return_value' => 1,
];
$input_settings = $this
->getSetting('input');
$form['input'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Geofield Settings'),
];
$form['input']['show'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show geofield input element'),
'#default_value' => $input_settings['show'] ?? $default_settings['input']['show'],
];
$form['input']['readonly'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Make geofield input element read-only'),
'#default_value' => $input_settings['readonly'] ?? $default_settings['input']['readonly'],
'#states' => [
'invisible' => [
':input[name="fields[field_geofield][settings_edit_form][settings][input][show]"]' => [
'checked' => FALSE,
],
],
],
];
$toolbar_settings = $this
->getSetting('toolbar');
$form['toolbar'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Leaflet PM Settings'),
];
$form['toolbar']['position'] = [
'#type' => 'select',
'#title' => $this
->t('Toolbar position.'),
'#options' => [
'topleft' => 'topleft',
'topright' => 'topright',
'bottomleft' => 'bottomleft',
'bottomright' => 'bottomright',
],
'#default_value' => $toolbar_settings['position'] ?? $default_settings['toolbar']['position'],
];
$form['toolbar']['drawMarker'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to draw markers.'),
'#default_value' => $toolbar_settings['drawMarker'] ?? $default_settings['toolbar']['drawMarker'],
];
$form['toolbar']['drawPolyline'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to draw polyline.'),
'#default_value' => $toolbar_settings['drawPolyline'] ?? $default_settings['toolbar']['drawPolyline'],
];
$form['toolbar']['drawRectangle'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to draw rectangle.'),
'#default_value' => $toolbar_settings['drawRectangle'] ?? $default_settings['toolbar']['drawRectangle'],
];
$form['toolbar']['drawPolygon'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to draw polygon.'),
'#default_value' => $toolbar_settings['drawPolygon'] ?? $default_settings['toolbar']['drawPolygon'],
];
$form['toolbar']['drawCircle'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to draw circle. (unsupported by GeoJSON'),
'#default_value' => $toolbar_settings['drawCircle'] ?? $default_settings['toolbar']['drawCircle'],
'#disabled' => TRUE,
];
$form['toolbar']['drawCircleMarker'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to draw circle marker. (unsupported by GeoJSON'),
'#default_value' => $toolbar_settings['drawCircleMarker'] ?? $default_settings['toolbar']['drawCircleMarker'],
'#disabled' => TRUE,
];
$form['toolbar']['editMode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to toggle edit mode for all layers.'),
'#default_value' => $toolbar_settings['editMode'] ?? $default_settings['toolbar']['editMode'],
];
$form['toolbar']['dragMode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to toggle drag mode for all layers.'),
'#default_value' => $toolbar_settings['dragMode'] ?? $default_settings['toolbar']['dragMode'],
];
$form['toolbar']['cutPolygon'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to cut hole in polygon.'),
'#default_value' => $toolbar_settings['cutPolygon'] ?? $default_settings['toolbar']['cutPolygon'],
];
$form['toolbar']['removalMode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adds button to remove layers.'),
'#default_value' => $toolbar_settings['removalMode'] ?? $default_settings['toolbar']['removalMode'],
];
// Generate the Leaflet Map Reset Control.
$this
->setResetMapControl($form, $this
->getSettings());
// Set Map Geometries Options Element.
$this
->setMapPathOptionsElement($form, $this
->getSettings());
// Set Replacement Patterns Element.
$this
->setReplacementPatternsElement($form);
// Set Map Geocoder Control Element, if the Geocoder Module exists,
// otherwise output a tip on Geocoder Module Integration.
$this
->setGeocoderMapControl($form, $this
->getSettings());
return $form;
}