summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Petsovits2008-06-27 16:16:15 (GMT)
committer Jakob Petsovits2008-06-27 16:16:15 (GMT)
commitf7d291267be8c4ee8d82773039e05afacd7c9d19 (patch)
treed8a710c45d7f5ddff045e0eee578e37b02baab7c
parent6de16723a3cfc289f7c3d1c5d3a8c23413c90782 (diff)
Use the new field_file_save_upload() function, and let modules
specify their own validators.
-rw-r--r--filefield.module20
1 files changed, 8 insertions, 12 deletions
diff --git a/filefield.module b/filefield.module
index 6561165..1bb969c 100644
--- a/filefield.module
+++ b/filefield.module
@@ -515,9 +515,10 @@ function filefield_file_upload(&$form_state, $field, $delta) {
$widget_file_path = $field['widget']['file_path'];
}
- $validators = array(
+ // Let modules provide their own validators.
+ $validators = array_merge(module_invoke_all('filefield_validators'), array(
'file_validate_extensions' => array($field['widget']['file_extensions']),
- );
+ ));
$upload_name = $field_name .'_'. $delta;
$complete_file_path = file_directory_path() .'/'. $widget_file_path;
@@ -526,17 +527,18 @@ function filefield_file_upload(&$form_state, $field, $delta) {
$file = array('fid' => 0, 'replaced_file' => $replaced_file);
return $file;
}
- if (!$file = file_save_upload($upload_name, $validators, $complete_file_path)) {
- watchdog('file', 'The file %file could not be saved as addition to the file field %field (content type %type). This can be a consequence of the file failing validation, or if it can\'t be moved to the file directory, or whatever reason the file_save_upload() function comes up with. No further information is available to the filefield module, but if you\'re lucky then that function left one or more hints in the log as well (directly before this log entry).', array('%file' => $complete_file_path, '%field' => $field_name, '%type' => $field['type_name']));
+
+ if (!$file = field_file_save_upload($upload_name, $validators, $complete_file_path)) {
+ watchdog('file', 'The file %file could not be saved as addition to the file field %field (content type %type). This can be a consequence of the file failing validation, or if it can\'t be moved to the file directory, or whatever reason the file framework comes up with. No further information is available to the filefield module, but if you\'re lucky then that function left one or more hints in the log as well (directly before this log entry).', array('%file' => $complete_file_path, '%field' => $field_name, '%type' => $field['type_name']));
$file = array('fid' => 0, 'replaced_file' => $replaced_file);
return $file;
}
$file_default_properties = array(
'list' => 1,
- 'description' => $file->filename,
+ 'description' => $file['filename'],
);
- $file = array_merge($file_default_properties, (array) $file);
+ $file = array_merge($file_default_properties, $file);
$file['replaced_file'] = $replaced_file;
return $file;
}
@@ -876,12 +878,6 @@ function _filefield_widget_prepare_form_values($node, $field, &$items) {
if ($file = file_check_upload($field_name .'_upload')) {
$file = (array)$file;
- // let extended validation from other module happen so we get all error messages.
- // if you implement hook_filefield_file() return FALSE to stop the upload.
- if (empty($errors)) {
- $errors = module_invoke_all('filefield', 'file_validate', $node, $field, $file);
- }
-
// let modules massage act on the file.
foreach(module_implements('filefield') as $module) {
$function = $module .'_filefield';