diff --git a/UPGRADE.txt b/UPGRADE.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb37b301d5f877db2486e272e978aad86d724525 --- /dev/null +++ b/UPGRADE.txt @@ -0,0 +1,23 @@ +Upgrading from 5.x-2.x to 6.x-2.x + + + + + + + + + + + + + + + +MODULE DEVELOPERS: + +Upgrading from 5.x-2.x to 6.x-2.x + the field type for filefields has changed from 'file' to 'filefield'. + I suggest you just reread the whole module... + + diff --git a/filefield.module b/filefield.module index 176540bb1dd5d4b59df267ee5607d06c0cf8b9af..33eb78a49df87a4d531cbd45acc4ef5cad6e6140 100644 --- a/filefield.module +++ b/filefield.module @@ -85,20 +85,29 @@ function filefield_elements() { */ function filefield_theme() { return array( + 'filefield_file' => array( + 'arguments' => array('file' => NULL), + 'file' => 'filefield_formatter.inc', + ), + 'filefield_icon' => array( + 'arguments' => array('file' => NULL), + 'file' => 'filefield.theme.inc', + ), 'filefield_widget' => array( 'arguments' => array('element' => NULL), 'file' => 'filefield_widget.inc', ), + + 'filefield_formatter_filefield_default' => array( + 'arguments' => array('element' => NULL), + 'file' => 'filefield_formatter.inc', + ), // @todo: verify the need for the rest one by one. 'filefield_container_item' => array( 'arguments' => array('element' => NULL), 'file' => 'filefield.theme.inc', ), - 'filefield_icon' => array( - 'arguments' => array('file' => NULL), - 'file' => 'filefield.theme.inc', - ), 'filefield_file_upload' => array( 'arguments' => array('element' => NULL), 'file' => 'filefield_widget.inc', @@ -113,21 +122,15 @@ function filefield_theme() { ), 'filefield_formatter_default' => array( 'arguments' => array('element' => NULL), - 'file' => 'filefield.formatter.inc', + 'file' => 'filefield_formatter.inc', ), 'filefield_unguarded' => array( 'arguments' => array('file' => NULL, 'field' => NULL), - 'file' => 'filefield.formatter.inc', + 'file' => 'filefield_formatter.inc', ), 'filefield' => array( 'arguments' => array('file' => NULL, 'field' => NULL), - 'file' => 'filefield.formatter.inc', - ), - 'filefield_file_formatter_generic' => array( - 'arguments' => array( - 'file' => NULL, 'field' => NULL, 'file_formatter_settings' => NULL, - ), - 'file' => 'filefield.formatter.inc', + 'file' => 'filefield_formatter.inc', ), ); } @@ -329,7 +332,7 @@ function filefield_field_formatter_info() { 'filefield_default' => array( 'label' => t('Generic files'), 'suitability callback' => TRUE, - 'field types' => array('file','image'), + 'field types' => array('filefield','image'), 'multiple values' => CONTENT_HANDLE_CORE, 'description' => t('Displays all kinds of files with an icon and a linked file description.'), ), diff --git a/filefield.formatter.inc b/filefield_formatter.inc similarity index 86% rename from filefield.formatter.inc rename to filefield_formatter.inc index a30f91e7f1818a572fbaafd1ec7a6a0b8c48a995..5ce7fd33bfd7946e016cb8757a85237621c8ee47 100644 --- a/filefield.formatter.inc +++ b/filefield_formatter.inc @@ -13,10 +13,9 @@ /** * Theme function for the 'default' filefield formatter. */ -function theme_filefield_formatter_default($element) { +function theme_filefield_formatter_filefield_default($element) { $file = $element['#item']; - $field = content_fields($element['#field_name']); - return theme('filefield', $file, $field); + return 'filefiedl' . theme('filefield', $file); } /** @@ -77,10 +76,10 @@ function theme_filefield_unguarded($file, $field) { /** * Theme function for the 'generic' single file formatter. */ -function theme_filefield_file_formatter_generic($file, $field, $file_formatter_settings) { - $path = $file->filepath; +function theme_filefield_file($file) { + $path = $file['filepath']; $url = file_create_url($path); $icon = theme('filefield_icon', $file); - $desc = $file->description; - return '
'. $icon . l($desc, $url) .'
'; + $desc = $file['description']; + return '
'. $icon . l($desc, $url) .'
'; } diff --git a/filefield_widget.inc b/filefield_widget.inc index b1ef4d456d851b89404c5bfafc473b2de7ad81ff..0f433fa3f78bbecce29126f24d21a5f84192e32d 100644 --- a/filefield_widget.inc +++ b/filefield_widget.inc @@ -22,8 +22,8 @@ function filefield_widget_value($element, $edit = FALSE) { $file = field_file_load($edit['fid']); $item = array( 'fid' => $edit['fid'], - 'alt' => $edit['alt'], - 'title' => $edit['title'], + 'description' => $edit['description'], + 'list' => empty($edit['list']), 'data' => '', ); } @@ -43,7 +43,7 @@ function filefield_widget_process($element, $edit, &$form_state, $form) { $element['fid'] = array('#type' => 'hidden', '#value' => $file['fid']); if ($file['fid'] != 0) { - $element['preview'] = array('#type' => 'markup', '#value' => theme('imagefield_item', $file)); + $element['preview'] = array('#type' => 'markup', '#value' => theme('filefield_file', $file)); if (empty($file['filepath'])) { //dsm($file); } @@ -70,7 +70,7 @@ function filefield_widget_process($element, $edit, &$form_state, $form) { '#name' => $field_name .'_'. $delta .'_remove_btn', '#type' => 'submit', '#value' => t('Remove'), - '#submit' => array('imagefield_widget_submit_remove_btn'), + '#submit' => array('filefield_widget_submit_remove_btn'), '#field_name' => $field_name, '#delta' => $delta, ); @@ -90,7 +90,7 @@ function filefield_widget_process($element, $edit, &$form_state, $form) { '#name' => $field_name .'_'. $delta .'_upload_btn', '#type' => 'submit', '#value' => t('Upload'), - '#submit' => array('imagefield_widget_submit_upload_btn'), + '#submit' => array('filefield_widget_submit_upload_btn'), '#field_name' => $field_name, '#delta' => $delta, ); @@ -138,11 +138,7 @@ function filefield_widget_submit_upload_btn($form, &$form_state) { return $file; } - $validators = array( - 'file_validate_extensions' => array($field['widget']['file_extensions']), - 'file_validate_size' => array($field['widget']['max_filesize']), - 'file_validate_image_resolution' => array($field['widget']['max_resolution']), - ); + $validators = _filefield_filefield_validators($field, $field['widget'], $form_state['values'][$field_name]); if (!$file = field_file_save_upload($upload_name, $validators, $complete_file_path)) { watchdog('imagefield', 'The file upload failed. %upload', array('%upload' => $upload_name)); @@ -476,9 +472,7 @@ function _filefield_filefield_validators($field, $widget, $existing_files) { // Thanks to the php.ini restrictions, there is always a maximum file size. // Therefore we can rely on at least one restriction always being in force. - $max_filesize = _filefield_maximum_filesize( - $field, $widget, $existing_files - ); + $max_filesize = _filefield_maximum_filesize($field, $widget, $existing_files); $filesize_message = ($max_filesize > 0) ? t('Maximum file size: !size.', array('!size' => format_size($max_filesize))) : t('The allowed maximum file size total has been exceeded.'); @@ -497,16 +491,6 @@ function _filefield_filefield_validators($field, $widget, $existing_files) { )), ); } - - $supported_file_widgets = _filefield_supported_file_widgets($widget); - if (!empty($supported_file_widgets)) { - $validators['filefield_validate_file_widget_support'] = array( - 'validator arguments' => array($field, $widget, $supported_file_widgets), - 'requirement message' => t('Uploads are restricted to the following categories: !widgets.', array( - '!widgets' => implode(', ', $supported_file_widgets), - )), - ); - } return $validators; }