function imageblock_configure_form_validate in Image Block 7
Same name and namespace in other branches
- 6 imageblock.module \imageblock_configure_form_validate()
2 string references to 'imageblock_configure_form_validate'
- imageblock_add_block_form in ./
imageblock.admin.inc - Form builder for the add image block form.
- imageblock_form_alter in ./
imageblock.module - Implements hook_form_alter().
File
- ./
imageblock.module, line 293 - imageblock.module Primarily Drupal hooks.
Code
function imageblock_configure_form_validate($form, &$form_state) {
// TODO: make these settings, make this work
// Check if already exists this block description to prevent a PDO exception.
if ($form['#form_id'] == 'imageblock_add_block_form') {
$info = $form_state['values']['info'];
$duplicate_desc = db_query('SELECT count(info) FROM {imageblock} WHERE info = :info', array(
':info' => $info,
))
->fetchField();
if ($duplicate_desc) {
form_set_error('imageblock_duplicate', t("Failed to create block. A block with this description already exists. Please edit your block description and try again."));
}
}
$validators['file_validate_is_image'] = array();
if ($max = variable_get('imageblock_max_file_size', 0)) {
$validators['file_validate_size'] = array(
parse_size($max),
0,
);
}
if ($max = variable_get('imageblock_max_dimensions', 0)) {
$validators['file_validate_image_resolution'] = array(
$max,
);
}
// Save new file uploads.
$file = file_save_upload('imageblock', $validators);
if ($file === FALSE) {
form_set_error('imageblock', t("Failed to upload the image; the %directory directory doesn't exist or is not writable.", array(
'%directory' => variable_get('imageblock_image_path', 'imageblock'),
)));
}
elseif ($file !== NULL) {
$form_state['values']['imageblock_file'] = $file;
}
}