You are here

function jw_player_ctools_export_ui_form_validate in JW Player 7.2

Same name and namespace in other branches
  1. 7 plugins/export_ui/jw_player_ctools_export_ui.inc \jw_player_ctools_export_ui_form_validate()

Validator for jw_player_ctools_export_ui_form().

1 string reference to 'jw_player_ctools_export_ui_form_validate'
jw_player_ctools_export_ui.inc in plugins/export_ui/jw_player_ctools_export_ui.inc

File

plugins/export_ui/jw_player_ctools_export_ui.inc, line 498

Code

function jw_player_ctools_export_ui_form_validate($form, &$form_state) {
  $settings = $form_state['values']['settings'];

  // If sharing is empty, remove selected options from sharing sites
  // field, and reset sharing heading text.
  if (array_key_exists('sharing', $settings) && $settings['sharing'] == 0) {
    $sharing = array();
    foreach ($settings['sharing_sites_show'] as $key => $value) {
      $sharing[$key] = 0;
    }
    form_set_value($form['settings']['sharing_sites_show'], $sharing, $form_state);
    form_set_value($form['settings']['sharing_heading'], t(''), $form_state);
  }

  // Use preset form if legacy or a version that is configured with local presets.
  if ($settings['preset_source'] == 'drupal') {
    if ($settings['responsive']) {

      // Width Percent Validation.
      if (empty($settings['width']) || !is_numeric($settings['width'])) {
        form_set_error('settings][width', t('Width field is required and must be a numeric value.'));
      }
      else {
        if ($settings['width'] <= 0 || $settings['width'] > 100) {
          form_set_error('settings][width', t('Width field must be greater than 0% and no more than 100%.'));
        }
      }

      // Aspect Ratio Validation.
      if (empty($settings['aspectratio'])) {
        form_set_error('settings][aspectratio', t('Aspect Ratio field is required if Responsive Design is enabled.'));
      }
      else {
        if (!preg_match('/^([0-9]*):([0-9]*)$/', $settings['aspectratio'], $matches) || (!is_numeric($matches[1]) || !is_numeric($matches[2]))) {
          form_set_error('settings][aspectratio', t('Aspect Ratio field must be of the format of two numbers separated by a colon. For example, <em>16:9</em>.'));
        }
      }
    }
    else {

      // Width Validation.
      if (empty($settings['width']) || !is_numeric($settings['width'])) {
        form_set_error('settings][width', t('Width field is required and must be a numeric value.'));
      }
      else {
        if ($settings['width'] <= 0) {
          form_set_error('settings][width', t('Width field must be greater than 0.'));
        }
      }

      // Height Validation.
      if (empty($settings['height']) || !is_numeric($settings['height'])) {
        form_set_error('settings][height', t('Height field is required and must be a numeric value.'));
      }
      else {
        if ($settings['height'] <= 0) {
          form_set_error('settings][height', t('Height field must be greater than 0.'));
        }
      }
    }
  }
  else {
    preg_match(jw_player_library_url_regex(), $settings['player_library_url'], $matches);
    if (!isset($matches[2])) {
      form_set_error('settings][player_library_url', t('Player Library URL does not match format provided by JWPlayer.com.'));
    }
  }
}