summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrew morton2008-08-16 20:09:52 (GMT)
committer andrew morton2008-08-16 20:09:52 (GMT)
commitbf60267346af6b19be72b720c2b4d2136c437b0f (patch)
tree4fc02ab80cb762e9418de4cbd1254d5139c4f6e1
parent7e784adca9ee3d0cf9658a59bee0336b0fd8d6d0 (diff)
Added a filefield_widget_file_path() function to compute the widgets file path.
-rw-r--r--filefield_widget.inc24
1 files changed, 17 insertions, 7 deletions
diff --git a/filefield_widget.inc b/filefield_widget.inc
index 1b53d6f..91b9059 100644
--- a/filefield_widget.inc
+++ b/filefield_widget.inc
@@ -108,6 +108,22 @@ function _filefield_widget_settings_max_filesize_per_node_validate($element, &$f
}
}
+/**
+ * Determine the widget's files directory
+ *
+ * @param $field CCK field
+ * @return files directory path.
+ */
+function filefield_widget_file_path($field_instance) {
+ $dest = $field_instance['widget']['file_path'];
+ if (module_exists('token')) {
+ global $user;
+ $dest = token_replace($dest, 'user', $user);
+ }
+
+ return file_directory_path() .'/'. $dest;
+}
+
function filefield_save_upload($element) {
$upload_name = $element['#field_name'] .'_'. $element['#delta'];
$field_instance = content_fields($element['#field_name'], $element['#type_name']);
@@ -116,13 +132,7 @@ function filefield_save_upload($element) {
return 0;
}
- $dest = $field_instance['widget']['file_path'];
- if (module_exists('token')) {
- global $user;
- $dest = token_replace($dest, 'user', $user);
- }
-
- $dest = file_directory_path() .'/'. $dest;
+ $dest = filefield_widget_file_path($field_instance);
if (!field_file_check_directory($dest, FILE_CREATE_DIRECTORY)) {
watchdog('imagefield', 'The upload directory %directory for the file field %field (content type %type) could not be created or is not accessible. A newly uploaded file could not be saved in this directory as a consequence, and the upload was canceled.', array('%directory' => $dest, '%field' => $element['#field_name'], '%type' => $element['#type_name']));
form_set_error($upload_name, t('The file could not be uploaded.'));