// $Id: README.txt,v 1.1.2.2 2008/11/22 04:51:59 aland Exp $
This module provides two new form elements to assist with files that are stored/updated in Drupal's {files} table.
This module was programmed by Alan Davison @ www.caignwebs.com.au
Dependencies
------------
* none
Optimal integration
-------------------
* Image Cache (http://drupal.org/project/imagecache)
This module allows integration with Image Cache when saving
uploaded files.
Install
-------
Installing the Upload Element module is simple:
1) Copy the upload_element folder to the modules folder in your installation.
2) Enable the module using Administer -> Modules (/admin/build/modules)
Configuration for Upload Element
-------------------------------
No configuration is required.
Contributing
------------
All comments and patches welcome. Just visit the issue queue.
Support
-------
If you experience a problem with upload element or have a problem, file a
request or issue on the upload element queue at
http://drupal.org/project/issues/upload_element.
DO NOT POST IN THE FORUMS.
Posting in the issue queues is a direct line of communication with the module authors.
Usage
-----
The base usage can be as simple as:
## To add the element to the form
$form['image'] = array(
'#type' => 'image_upload_element',
'#title' => t('Image'),
'#default_value' => $node->image, // {files} object
);
## And to handle the submission
// in hook_insert or somewhere
// $node->image is a {files} object
// If you handle this yourself, make sure that you check
// the property submit_action to see if the object has
// been flagged as deleted.
$image_id = 0;
if($node->image) {
$image_id = upload_element_save($node->image, 'dest/directory', FILE_EXISTS_RENAME, 'imagecache_preset');
}
Configurable settings
---------------------
1) File validators
These are passed to file_save_upload during "hook_value", form_type_upload_element_value.
The image upload element has 'file_validate_is_image' automatically added.
Both elements get 'file_validate_size' added for theming purposes. This can be overridden
with a custom theme_upload_element_file_description($element).
This is adjusted to file_upload_max_size() if this is lower than the user defined size.
Even if set to file_upload_max_size(), PHP will drop the file or the entire form submission
if the upload size is exceeded, so these do not get passed to "hook_value".
While the text must be changed with a custom theme, the message seperator can be set using
'#file_validator_seperator'. This is defaulted to '
'
2) Images
There are two main settings of interest.
i) Image preview size
This can be used to change the image thumb on the form.
Eg: '#image_preview_size' => '100x100',
ii) Image preview default image
This replaces the simple "no image" image.
Eg: '#image_preview_default_image' => drupal_get_path('module', 'cw') .'/no_image2.GIF',
3) Themes
There are a number of possible theming functions:
i) Element theming functions
Takes full control of the element theming.
Note that theme_image_upload_element simply calls theme_upload_element
ii) Theming the filename preview
The theme_upload_element_preview themes the filename.
To override just a one off element, pass the theme function name as a '#file_formatter'
iii) Theming the image preview
Override theme_upload_element_image_preview
To override just a one off element, pass the theme function name as a '#image_formatter'
iv) Theming the description under the file input control.
Override theme_upload_element_file_description
##############################################################################################################
###### The demo version that is running @ http://www.caignwebs.com.au/contributions/node/2 ######
##############################################################################################################
Adding an image and a file to a node
------------------------------------
1) Create a new module info file: "cw.info"
--------------------------------------------------------------------------------------------------------------
name = Upload example demo
description = A module to demo/test the upload field.
package = Other
core = 6.x
--------------------------------------------------------------------------------------------------------------
2) Create an install file to create a new table to store the information: "cw.install"
--------------------------------------------------------------------------------------------------------------
$t('Additional upload element example fields.'),
'fields' => array(
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => $t('Primary Key: The {node}.nid of the node.')),
'fid1' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => $t('Index: The {files}.fid of the image file.')),
'fid2' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => $t('Index: The {files}.fid of the file.')),
'fid3' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => $t('Index: The {files}.fid of the image file.')),
'fid3_alt' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => $t('Custom ALT attribute of the image.')),
'fid3_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => $t('Custom TITLE attribute of the image.')),
'fid3_copyright' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => $t('Copyright details of the image.')),
'fid4' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => $t('Index: The {files}.fid of the file.')),
'fid4_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => $t('Custom TITLE of the file.')),
),
'primary key' => array('nid'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function cw_install() {
drupal_install_schema('cw');
}
/**
* Implementation of hook_uninstall().
*/
function cw_uninstall() {
drupal_uninstall_schema('cw');
}
--------------------------------------------------------------------------------------------------------------
3) Create the hooks required to hook into a node form: "cw.module"
In this example, we are using a custom 'upload_element_example' content type as the type to add the two fields to.
a) Using hook_form_alter to add the new fields to the node edit form
b) Using hook_nodeapi op save to save the data
c) Also using the hook_nodeapi ops load and view to present the files
The example shows how to add new elements into the upload element.
--------------------------------------------------------------------------------------------------------------
type == 'upload_element_example') {
$form['#attributes'] = array("enctype" => "multipart/form-data");
$form['fid2'] = array(
'#type' => 'upload_element',
'#title' => t('File 1'),
'#required' => FALSE,
'#default_value' => $node->fid2,
'#file_validators' => array('file_validate_size' => array(32768)),
);
$form['fid4'] = array(
'#type' => 'upload_element',
'#title' => t('File 2'),
'#required' => FALSE,
'#default_value' => $node->fid4,
'#file_validators' => array(
'file_validate_size' => array(16384),
'file_validate_extensions' => array('txt gif patch diff jpg jpeg'),
),
);
$form['fid4']['fid4_info'] = array(
'#type' => 'markup',
'#value' => '