You are here

public function LeafletWidget::settingsForm in Leaflet Widget for Geofield 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/LeafletWidget.php \Drupal\leaflet_widget\Plugin\Field\FieldWidget\LeafletWidget::settingsForm()

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 GeofieldDefaultWidget::settingsForm

File

src/Plugin/Field/FieldWidget/LeafletWidget.php, line 122

Class

LeafletWidget
Plugin implementation of the "leaflet_widget" widget.

Namespace

Drupal\leaflet_widget\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  parent::settingsForm($form, $form_state);
  $map_settings = $this
    ->getSetting('map');
  $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'],
    '#required' => TRUE,
  ];
  $form['map']['height'] = [
    '#title' => $this
      ->t('Height'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => $map_settings['height'],
  ];
  $form['map']['center'] = [
    '#type' => 'fieldset',
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
    '#title' => 'Default map center',
  ];
  $form['map']['center']['lat'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Latitude'),
    '#default_value' => $map_settings['center']['lat'],
    '#required' => TRUE,
  ];
  $form['map']['center']['lng'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Longtitude'),
    '#default_value' => $map_settings['center']['lng'],
    '#required' => TRUE,
  ];
  $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'],
  ];
  $form['map']['zoom'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Default zoom level'),
    '#default_value' => $map_settings['zoom'],
    '#required' => TRUE,
  ];
  $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'],
  ];
  $form['input']['readonly'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Make geofield input element read-only'),
    '#default_value' => $input_settings['readonly'],
    '#states' => [
      'invisible' => [
        ':input[name="fields[field_geofield][settings_edit_form][settings][input][show]"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  return $form;
}