public function OpenlayersWidgetBase::settingsForm in Openlayers 8.4
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form definition for the widget settings.
Overrides WidgetBase::settingsForm
2 calls to OpenlayersWidgetBase::settingsForm()
- OpenlayersGeofieldWidget::settingsForm in modules/
openlayers_geofield/ src/ Plugin/ Field/ FieldWidget/ OpenlayersGeofieldWidget.php - Returns a form to configure settings for the widget.
- OpenlayersGeolocationWidget::settingsForm in modules/
openlayers_geolocation/ src/ Plugin/ Field/ FieldWidget/ OpenlayersGeolocationWidget.php - Returns a form to configure settings for the widget.
2 methods override OpenlayersWidgetBase::settingsForm()
- OpenlayersGeofieldWidget::settingsForm in modules/
openlayers_geofield/ src/ Plugin/ Field/ FieldWidget/ OpenlayersGeofieldWidget.php - Returns a form to configure settings for the widget.
- OpenlayersGeolocationWidget::settingsForm in modules/
openlayers_geolocation/ src/ Plugin/ Field/ FieldWidget/ OpenlayersGeolocationWidget.php - Returns a form to configure settings for the widget.
File
- src/
Plugin/ Field/ FieldWidget/ OpenlayersWidgetBase.php, line 98
Class
- OpenlayersWidgetBase
- Base class for the field widget when displaying an Openlayers map.
Namespace
Drupal\openlayers\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$settings = $this
->getSettings();
$form['#tree'] = TRUE;
$field_name = $this->fieldDefinition
->getName();
$mapNames = \Drupal::service('config.storage')
->listAll('openlayers.map');
$map_options = [];
foreach ($mapNames as $mapName) {
$mapLabel = \Drupal::config($mapName)
->get('label');
$mapName = str_replace('openlayers.map.', '', $mapName);
$map_options[$mapName] = $mapLabel;
}
$form['map'] = [
'#title' => $this
->t('Openlayers Map'),
'#type' => 'select',
'#description' => $this
->t('Select the map you wish to use.'),
'#options' => $map_options,
'#empty_option' => $this
->t('-- select map --'),
'#default_value' => $settings['map'],
'#required' => TRUE,
'#weight' => -5,
];
$form['height'] = [
'#title' => $this
->t('Map Height'),
'#type' => 'number',
'#default_value' => $settings['height'],
'#description' => $this
->t('Note: This can be left empty to make the Map fill its parent container height.'),
'#weight' => -2,
];
$form['height_unit'] = [
'#title' => t('Map height unit'),
'#type' => 'select',
'#options' => [
'px' => t('px'),
'%' => t('%'),
],
'#default_value' => $settings['height_unit'],
'#description' => t("Whether height is absolute (pixels) or relative (percent).<br><strong>Note:</strong> In case of Percent the Openlayers Map should be wrapped in a container element with defined Height, otherwise won't show up."),
'#weight' => -1,
];
$form['initial_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Initial Settings (for empty map)'),
];
$form['initial_settings']['lat'] = [
'#type' => 'textfield',
'#title' => $this
->t('Latitude'),
'#default_value' => isset($settings['initial_settings']['lat']) ? $settings['initial_settings']['lat'] : 0,
'#required' => TRUE,
];
$form['initial_settings']['lon'] = [
'#type' => 'textfield',
'#title' => $this
->t('Longtitude'),
'#default_value' => isset($settings['initial_settings']['lon']) ? $settings['initial_settings']['lon'] : 0,
'#required' => TRUE,
];
$form['initial_settings']['zoom'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default zoom level'),
'#default_value' => isset($settings['initial_settings']['zoom']) ? $settings['initial_settings']['zoom'] : 10,
'#required' => TRUE,
'#description' => $this
->t('Zoom to be used for a single marker or a blank map'),
];
$form['input'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Geofield Settings'),
];
$form['input']['show'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show geofield input element'),
'#default_value' => $settings['input']['show'],
];
$form['input']['editable'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow editing of geofield input field'),
'#default_value' => $settings['input']['editable'],
'#states' => [
'invisible' => [
':input[name="fields[field_geofield][settings_edit_form][settings][input][show]"]' => [
'checked' => FALSE,
],
],
],
];
$form['toolbar'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Editing Toolbar settings'),
];
$form['toolbar']['position'] = [
'#type' => 'select',
'#title' => $this
->t('Toolbar position.'),
'#options' => [
'top' => 'top',
'bottom' => 'bottom',
'left' => 'left',
'right' => 'right',
'topleft' => 'topleft',
'topright' => 'topright',
'bottomleft' => 'bottomleft',
'bottomright' => 'bottomright',
],
'#default_value' => $settings['toolbar']['position'],
];
return $form;
}