You are here

public function LayerSwitcher::optionsForm in Openlayers 7.3

@TODO What is this return? If it is the form, why is form by reference?

Overrides Base::optionsForm

File

src/Plugin/Control/LayerSwitcher/LayerSwitcher.php, line 28
Control: LayerSwitcher.

Class

LayerSwitcher
Class LayerSwitcher.

Namespace

Drupal\openlayers\Plugin\Control\LayerSwitcher

Code

public function optionsForm(array &$form, array &$form_state) {
  $form['options']['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Title of the control'),
    '#default_value' => $this
      ->getOption('label', 'Layers'),
  );
  $form['options']['layers'] = array(
    '#type' => 'select',
    '#title' => t('Layers'),
    '#empty_option' => t('- Select a Layer -'),
    '#multiple' => TRUE,
    '#default_value' => $this
      ->getOption('layers'),
    '#options' => Openlayers::loadAllAsOptions('Layer'),
  );
  $form['options']['multiselect'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow selecting multiple layers'),
    '#default_value' => $this
      ->getOption('multiselect', FALSE),
  );
  $form['options']['layer_labels_hint'] = array(
    '#markup' => t('You need to save the configuration before being able to set custom layer labels.'),
  );
  $labels = $this
    ->getOption('layer_labels', array());
  foreach ((array) $this
    ->getOption('layers') as $i => $machine_name) {
    if (($map_layer = Openlayers::load('Layer', $machine_name)) == TRUE) {
      $label = check_plain($map_layer
        ->getName());
      if (isset($labels[$machine_name])) {
        $label = $labels[$machine_name];
      }
      $form['options']['layer_labels'][$machine_name] = array(
        '#type' => 'textfield',
        '#title' => t('Label for layer @label:', array(
          '@label' => $map_layer
            ->getName(),
        )),
        '#default_value' => $label,
      );
    }
  }

  // @TODO Add configuration for initial visibility. (Adjust JS accordingly)
  // @TODO Add configuration for ordering?
}