You are here

function coder_upgrade_conversions_form_validate in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/includes/conversion.inc \coder_upgrade_conversions_form_validate()

Validation handler for the module conversion form.

File

coder_upgrade/includes/conversion.inc, line 240

Code

function coder_upgrade_conversions_form_validate($form, &$form_state) {

  // Set keys to validate.
  $keys = coder_upgrade_selection_types($form_state);
  $count = 0;

  // Validate the user selections.
  $values = $form_state['values'];
  foreach ($values as $key => $list) {
    if (!in_array($key, $keys)) {
      continue;
    }
    $selections = coder_upgrade_selections_extract($list['list']);
    if (in_array($key, array(
      'upgrades',
      'extensions',
    )) && !count($selections)) {
      form_set_error($key, t('Please select at least one item in the %item tab.', array(
        '%item' => ucfirst($key),
      )));
    }
    elseif (in_array($key, array(
      'directories',
      'modules',
    ))) {
      $count += count($selections);
    }
  }

  // Determine if keys contains both 'directories' and 'modules'.
  $test = array_diff(array(
    'directories',
    'modules',
  ), $keys);
  if (!$count && empty($test)) {
    form_set_error($key, t('Please select at least one item in the %item1 or %item2 tabs.', array(
      '%item1' => ucfirst('directories'),
      '%item2' => ucfirst('modules'),
    )));
  }
}