You are here

function superfish_block_validate in Superfish 6

Same name and namespace in other branches
  1. 7 superfish.module \superfish_block_validate()

Validation function for the block configuration form.

1 string reference to 'superfish_block_validate'
superfish_form_block_admin_configure_alter in ./superfish.module
Implements hook_form_FORM_ID_alter().

File

./superfish.module, line 1158
Enables the use of jQuery Superfish plugin for Drupal menus.

Code

function superfish_block_validate($form, &$form_state) {
  if ($form_state['values']['module'] == 'superfish') {
    $supersubs_error = FALSE;
    $delta = $form_state['values']['delta'];
    $style = $form_state['values']['superfish_style_' . $delta];
    $speed = $form_state['values']['superfish_speed_' . $delta];
    $delay = $form_state['values']['superfish_delay_' . $delta];
    $pathclass = $form_state['values']['superfish_pathclass_' . $delta];
    $touch = $form_state['values']['superfish_touch_' . $delta];
    $touchbp = $form_state['values']['superfish_touchbp_' . $delta];
    $touchua = $form_state['values']['superfish_touchua_' . $delta];
    $touchual = $form_state['values']['superfish_touchual_' . $delta];
    $small = $form_state['values']['superfish_small_' . $delta];
    $smallbp = $form_state['values']['superfish_smallbp_' . $delta];
    $smallua = $form_state['values']['superfish_smallua_' . $delta];
    $smallual = $form_state['values']['superfish_smallual_' . $delta];
    $minwidth = $form_state['values']['superfish_minwidth_' . $delta];
    $maxwidth = $form_state['values']['superfish_maxwidth_' . $delta];
    $mcexclude = $form_state['values']['superfish_mcexclude_' . $delta];
    $hldmenus = $form_state['values']['superfish_hldmenus_' . $delta];
    $hldexclude = $form_state['values']['superfish_hldexclude_' . $delta];
    $extracss = $form_state['values']['superfish_pathcss_' . $delta];
    if ($style != 'none' && superfish_styles('path', $style) == '') {
      form_set_error('superfish_style_' . $delta, t('Cannot find the CSS file of the selected style.'));
    }
    elseif (!is_numeric($speed) && !in_array($speed, array(
      'slow',
      'normal',
      'fast',
    ))) {
      form_set_error('superfish_speed_' . $delta, t('<strong>Animation speed</strong>: unacceptable value entered.'));
    }
    if (!is_numeric($delay)) {
      form_set_error('superfish_delay_' . $delta, t('<strong>Mouse delay</strong>: unacceptable value entered.'));
    }
    if (is_numeric($pathclass)) {
      form_set_error('superfish_pathclass_' . $delta, t('<strong>Path class</strong>: unacceptable value entered.'));
    }
    if ($touch == 2 && $touchbp == '') {
      form_set_error('superfish_touchbp_' . $delta, t('<strong>sf-Touchscreen Breakpoint</strong>: field cannot be empty.'));
    }
    if (!is_numeric($touchbp)) {
      form_set_error('superfish_touchbp_' . $delta, t('<strong>sf-Touchscreen Breakpoint</strong>: unacceptable value entered.'));
    }
    if ($touch == 3 && $touchua == 1 && $touchual == '') {
      form_set_error('superfish_touchual_' . $delta, t('<strong>sf-Touchscreen Custom list of user agents</strong>: field cannot be empty.'));
    }
    if ($small == 2 && $smallbp == '') {
      form_set_error('superfish_smallbp_' . $delta, t('<strong>sf-Smallscreen Breakpoint</strong>: field cannot be empty.'));
    }
    if (!is_numeric($smallbp)) {
      form_set_error('superfish_smallbp_' . $delta, t('<strong>sf-Smallscreen Breakpoint</strong>: unacceptable value entered.'));
    }
    if ($small == 3 && $smallua == 1 && $smallual == '') {
      form_set_error('superfish_smallual_' . $delta, t('<strong>sf-Smallscreen Custom list of user agents</strong>: field cannot be empty.'));
    }
    if (!is_numeric($minwidth)) {
      form_set_error('superfish_minwidth_' . $delta, t('<strong>Supersubs minimum width</strong>: unacceptable value entered.'));
      $supersubs_error = TRUE;
    }
    if (!is_numeric($maxwidth)) {
      form_set_error('superfish_maxwidth_' . $delta, t('<strong>Supersubs maximum width</strong>: unacceptable value entered.'));
      $supersubs_error = TRUE;
    }
    if ($supersubs_error !== TRUE && $minwidth > $maxwidth) {
      form_set_error('superfish_maxwidth_' . $delta, t('Supersubs <strong>maximum width</strong> has to be bigger than the <strong>minimum width</strong>.'));
    }
    if (!empty($mcexclude) && (!is_numeric(str_replace(',', '', $mcexclude)) || strpos($mcexclude, '.'))) {
      form_set_error('superfish_mcexclude_' . $delta, t('<strong>Multi-column subs-menus</strong>: unacceptable value entered.'));
    }
    if (!empty($hldmenus) && (!is_numeric(str_replace(',', '', $hldmenus)) || strpos($hldmenus, '.'))) {
      form_set_error('superfish_hldmenus_' . $delta, t('<strong>Hyperlinks</strong>: unacceptable value entered.'));
    }
    if (!empty($hldexclude) && (!is_numeric(str_replace(',', '', $hldexclude)) || strpos($hldexclude, '.'))) {
      form_set_error('superfish_hldexclude_' . $delta, t('<strong>Hyperlinks</strong>: unacceptable value entered.'));
    }
    if (!empty($extracss)) {
      if (strpos($extracss, ',')) {
        $error = array();
        $extracss = superfish_array_filter(explode(',', $extracss));
        foreach ($extracss as $c) {
          if (!file_exists($c)) {
            $error[] = $c;
          }
        }
        if (!empty($error)) {
          form_set_error('superfish_pathcss_' . $delta, t('Cannot find the CSS file mentioned in <strong>Extra CSS</strong>'));
        }
      }
      elseif (!file_exists($extracss)) {
        form_set_error('superfish_pathcss_' . $delta, t('Cannot find the CSS file mentioned in <strong>Extra CSS</strong>'));
      }
    }
  }
}