Commit c3d9c528 authored by webchick's avatar webchick

#334303 by drewish: Handle overwriting of managed files, with tests.

parent 117b284f
This diff is collapsed.
This diff is collapsed.
......@@ -32,6 +32,16 @@ function _file_test_form(&$form_state) {
'#type' => 'file',
'#title' => t('Upload an image'),
);
$form['file_test_replace'] = array(
'#type' => 'select',
'#title' => t('Replace existing image'),
'#options' => array(
FILE_EXISTS_RENAME => t('Appends number until name is unique'),
FILE_EXISTS_REPLACE => t('Replace the existing file'),
FILE_EXISTS_ERROR => t('Fail with an error'),
),
'#default_value' => FILE_EXISTS_RENAME,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
......@@ -43,11 +53,13 @@ function _file_test_form(&$form_state) {
* Process the upload.
*/
function _file_test_form_submit(&$form, &$form_state) {
// Validate the uploaded picture.
$file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()));
// Process the upload and validate that it is an image. Note: we're using the
// form value for the $replace parameter.
$file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()), FALSE, $form_state['values']['file_test_replace']);
if ($file) {
$form_state['values']['file_test_upload'] = $file;
drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->filepath)));
drupal_set_message(t('You WIN!'));
}
else {
drupal_set_message(t('Epic upload FAIL!'), 'error');
......@@ -100,6 +112,18 @@ function file_test_get_calls($op) {
return $results[$op];
}
/**
* Get an array with the calls for all hooks.
*
* @return
* An array keyed by hook name ('load', 'validate', 'download',
* 'references', 'insert', 'update', 'copy', 'move', 'delete') with values
* being arrays of parameters passed to each call.
*/
function file_test_get_all_calls() {
return variable_get('file_test_results', array());
}
/**
* Store the values passed to a hook invocation.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment