You are here

public function IpGeoLocPluginStyleOpenLayers::buildOptionsForm in IP Geolocation Views & Maps 8

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/IpGeoLocPluginStyleOpenLayers.php, line 93

Class

IpGeoLocPluginStyleOpenLayers
Views Style plugin extension for OpenLayers (if enabled).

Namespace

Drupal\ip_geoloc\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['map'] = [
    '#type' => 'select',
    '#title' => t('Map'),
    '#description' => t('The OpenLayers map used to place the view locations on. You can configure map and markers <a href="/admin/structure/openlayers/maps">here</a>.'),
    '#options' => openlayers_map_options(),
    '#default_value' => isset($this->options['map']) ? $this->options['map'] : \Drupal::state()
      ->get('openlayers_default_map', 'default'),
  ];
  $form_state
    ->set('renderer', 'openlayers');
  $this->view_plugin_style
    ->pluginStyleBulkOfForm($this, $form, $form_state);

  // OpenLayers has "Hide empty map for Views" for this.
  unset($form['empty_map_center']);
  $form['center_option']['#options'][IP_GEOLOC_MAP_CENTER_ON_LOCATION_FROM_ARGUMENT] = t('Use lat/lon coordinate arguments from a contextual filter');
  $argument_handlers = $this->view->display_handler
    ->get_handlers('argument');
  if (!empty($argument_handlers)) {
    $argument_options = [
      '' => '<' . t('none') . '>',
    ];
    foreach ($argument_handlers as $key => $handler) {
      $argument_options[$key] = $handler->definition['group'] . ': ' . $handler->definition['title'];
    }
    $form['argument'] = [
      '#type' => 'select',
      '#title' => t('Choose a contextual filter to pull data from'),
      '#options' => $argument_options,
      '#default_value' => $this->options['argument'],
      '#weight' => 100,
    ];
  }
}