You are here

public function GeolocationBlock::blockSubmit in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Block/GeolocationBlock.php \Drupal\geolocation\Plugin\Block\GeolocationBlock::blockSubmit()

Overrides BlockPluginTrait::blockSubmit

File

src/Plugin/Block/GeolocationBlock.php, line 289

Class

GeolocationBlock
Exposes a map rendered as a block.

Namespace

Drupal\geolocation\Plugin\Block

Code

public function blockSubmit($form, FormStateInterface $form_state) {
  $this->configuration['map_provider_id'] = $form_state
    ->getValue('map_provider_id');
  $this->configuration['map_provider_settings'] = $form_state
    ->getValue('map_provider_settings');
  $this->configuration['centre'] = $form_state
    ->getValue('centre');
  $this->configuration['locations'] = [];
  $locations = $form_state
    ->getValue('locations');
  foreach ($locations as $index => $location) {
    if ($index === 'add_item') {
      continue;
    }
    if (!empty($location['marker_coordinates'])) {
      $location_item = [
        'marker_title' => '',
        'marker_content' => '',
        'marker_coordinates' => $location['marker_coordinates'],
      ];
      if (!empty($location['marker_title'])) {
        $location_item['marker_title'] = $location['marker_title'];
      }
      if (!empty($location['marker_content'])) {
        $location_item['marker_content'] = $location['marker_content'];
      }
      $this->configuration['locations'][] = $location_item;
    }
  }
}