You are here

function designkit_upload_validate in DesignKit 6

Same name and namespace in other branches
  1. 7 designkit.admin.inc \designkit_upload_validate()

Element validator for image upload. Handles file creation and value setting tasks all at once.

1 string reference to 'designkit_upload_validate'
_designkit_form_alter in ./designkit.admin.inc
Implementation of hook_form_alter() for spaces_features_form, system_theme_settings.

File

./designkit.admin.inc, line 152

Code

function designkit_upload_validate($element, &$form_state) {
  $name = end($element['#parents']);

  // Clean out upload values.
  unset($form_state['values'][$name]);

  // Save uploaded file.
  $validators = array(
    'file_validate_is_image' => array(),
    'file_validate_image_resolution' => array(
      '3000x3000',
    ),
    'file_validate_size' => array(
      1000 * 1024,
    ),
  );
  $file = file_save_upload($name, $validators, file_directory_path());
  $error = $file ? file_validate_is_image($file) : FALSE;

  // Save the new file & settings.
  if ($file && !$error) {
    file_set_status($file, 1);
    imagecache_image_flush($file->filepath);
    $form_state['values']['designkit_image'][$name] = $file->fid;

    // @TODO: Implement an autocolor key in the designkitinfo file spec
    // so that images can be related to colors.
    // $form_state['values']['designkit_color'] =
    //   designkit_image_autocolor($file->filepath) ?
    //   designkit_image_autocolor($file->filepath) :
    //   $form_state['values']['designkit_color'];
  }
  else {
    if ($error) {
      form_set_error($name, $error);
    }
    if ($file) {
      file_delete($file->filepath);
      db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
    }
    $form_state['values']['designkit_image'][$name] = 0;
  }
}