You are here

public function CommonMap::validateOptionsForm in Geolocation Field 8

Validate the options form.

Overrides StylePluginBase::validateOptionsForm

File

src/Plugin/views/style/CommonMap.php, line 868

Class

CommonMap
Allow to display several field items on a common map.

Namespace

Drupal\geolocation\Plugin\views\style

Code

public function validateOptionsForm(&$form, FormStateInterface $form_state) {
  parent::validateOptionsForm($form, $form_state);
  $values = $form_state
    ->getValues()['style_options'];
  $marker_clusterer_styles = $values['marker_clusterer_styles'];
  if (!empty($marker_clusterer_styles)) {
    if (!is_string($marker_clusterer_styles)) {
      $form_state
        ->setErrorByName('style_options][marker_clusterer_styles', $this
        ->t('Please enter a JSON string as style.'));
    }
    $json_result = json_decode($marker_clusterer_styles);
    if ($json_result === NULL) {
      $form_state
        ->setErrorByName('style_options][marker_clusterer_styles', $this
        ->t('Decoding style JSON failed. Error: %error.', [
        '%error' => json_last_error(),
      ]));
    }
    elseif (!is_array($json_result)) {
      $form_state
        ->setErrorByName('style_options][marker_clusterer_styles', $this
        ->t('Decoded style JSON is not an array.'));
    }
  }
  $this
    ->validateGoogleMapsSettingsForm($form, $form_state, 'style_options');
}