You are here

public function ip_geoloc_plugin_style_leaflet::options_validate in IP Geolocation Views & Maps 7

Validate the options form.

Overrides views_plugin_style::options_validate

File

views/ip_geoloc_plugin_style_leaflet.inc, line 1012

Class

ip_geoloc_plugin_style_leaflet

Code

public function options_validate(&$form, &$form_state) {
  ip_geoloc_plugin_style_bulk_of_form_validate($form, $form_state);
  $style_options = $form_state['values']['style_options'];
  $map_height = trim($style_options['map_height']);
  if (is_numeric($map_height) && $map_height <= 0) {
    form_error($form['map_height'], t('Map height must be a positive number.'));
  }
  $selected_map = ip_geoloc_plugin_style_leaflet_map_get_info($style_options['map']);
  $zoom_top = 18;
  if (isset($selected_map['settings']['maxZoom'])) {
    $zoom_top = $selected_map['settings']['maxZoom'];
  }
  $max_zoom = $style_options['map_options']['maxzoom'];
  if ($max_zoom != '' && (!is_numeric($max_zoom) || $max_zoom < 0 || $max_zoom > $zoom_top)) {
    form_error($form['map_options']['maxzoom'], t('"Maximum zoom level" for %map must be in range 0..@zoomtop', array(
      '%map' => $selected_map['label'],
      '@zoomtop' => $zoom_top,
    )));
  }
  $zoom = $style_options['map_options']['zoom'];
  if ($zoom != '' && (!is_numeric($zoom) || $zoom < 0 || $zoom > $max_zoom)) {
    form_error($form['map_options']['zoom'], t('"Initial zoom level" must be a non-negative number not greater than "Maximum zoom level".'));
  }
  $disable_zoom = $style_options['disable_clustering_at_zoom'];
  if ($disable_zoom != '' && (!is_numeric($disable_zoom) || $disable_zoom < 0 || $disable_zoom > $max_zoom)) {
    form_error($form['disable_clustering_at_zoom'], t('"Disable clustering at zoom" level must be a positive number not greater than "Maximum zoom level".'));
  }
  if (isset($style_options['cluster_aggregation'])) {
    $cluster_aggregation = $style_options['cluster_aggregation'];
    if (!empty($cluster_aggregation['aggregation_field'])) {
      $aggregation_field_info = field_info_field($cluster_aggregation['aggregation_field']);
      $valid_types = array(
        'number_integer',
        'number_decimal',
        'number_float',
        'entityreference',
      );
      if (!$aggregation_field_info || !in_array($aggregation_field_info['type'], $valid_types)) {
        drupal_set_message(t('A cluster aggregation field that cannot be interpreted as a number may cause unexpected errors.'));
      }
    }
  }
}