|
@@ -889,7 +889,8 @@ function tripal_element_info() {
|
|
*/
|
|
*/
|
|
function tripal_html5_file_process($element, $form_state, $complete_form) {
|
|
function tripal_html5_file_process($element, $form_state, $complete_form) {
|
|
|
|
|
|
- $type = $element['#usage_id'] . '-' . $element['#usage_type'];
|
|
|
|
|
|
+ $module = array_key_exists('#usage_module', $element) ? $element['#usage_module'] : 'tripal';
|
|
|
|
+ $type = $element['#usage_id'] . '-' . $element['#usage_type'] . '-' . $module;
|
|
$name = $element['#name'];
|
|
$name = $element['#name'];
|
|
$name = preg_replace('/[^\w]/', '_', $name);
|
|
$name = preg_replace('/[^\w]/', '_', $name);
|
|
|
|
|
|
@@ -963,37 +964,38 @@ function tripal_html5_file_validate($element, &$form_state) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Implements hook_handle_uplaoded_file().
|
|
|
|
|
|
+ * Implements hook_handle_uploaded_file().
|
|
*/
|
|
*/
|
|
function tripal_handle_uploaded_file($filename, $filepath, $type) {
|
|
function tripal_handle_uploaded_file($filename, $filepath, $type) {
|
|
|
|
|
|
global $user;
|
|
global $user;
|
|
|
|
|
|
|
|
+ // Create a file object.
|
|
|
|
+ $file = new stdClass();
|
|
|
|
+ $file->uri = $filepath;
|
|
|
|
+ $file->filename = $filename;
|
|
|
|
+ $file->filemime = file_get_mimetype($filepath);
|
|
|
|
+ $file->uid = $user->uid;
|
|
|
|
+ $file->status = FILE_STATUS_PERMANENT;
|
|
|
|
+ $file = file_save($file);
|
|
|
|
+
|
|
// Split the type into a node ID and form_key
|
|
// Split the type into a node ID and form_key
|
|
- list($nid, $form_key) = explode('-', $type);
|
|
|
|
|
|
+ list($id, $form_key) = explode('-', $type);
|
|
|
|
|
|
// See if this file is already managed then add another entry fin the
|
|
// See if this file is already managed then add another entry fin the
|
|
// usage table.
|
|
// usage table.
|
|
$fid = db_select('file_managed', 'fm')
|
|
$fid = db_select('file_managed', 'fm')
|
|
- ->fields('fm', array('fid'))
|
|
|
|
- ->condition('uri', $filepath)
|
|
|
|
- ->execute()
|
|
|
|
- ->fetchField();
|
|
|
|
|
|
+ ->fields('fm', array('fid'))
|
|
|
|
+ ->condition('uri', $filepath)
|
|
|
|
+ ->execute()
|
|
|
|
+ ->fetchField();
|
|
|
|
+
|
|
if ($fid) {
|
|
if ($fid) {
|
|
$file = file_load($fid);
|
|
$file = file_load($fid);
|
|
- file_usage_add($file, 'tripal', $form_key, $nid);
|
|
|
|
|
|
+ file_usage_add($file, 'tripal', $form_key, $id);
|
|
return $fid;
|
|
return $fid;
|
|
}
|
|
}
|
|
|
|
|
|
- // Create a file object.
|
|
|
|
- $file = new stdClass();
|
|
|
|
- $file->uri = $filepath;
|
|
|
|
- $file->filename = $filename;
|
|
|
|
- $file->filemime = file_get_mimetype($filepath);
|
|
|
|
- $file->uid = $user->uid;
|
|
|
|
- $file->status = FILE_STATUS_PERMANENT;
|
|
|
|
- $file = file_save($file);
|
|
|
|
-
|
|
|
|
return $file->fid;
|
|
return $file->fid;
|
|
}
|
|
}
|
|
|
|
|