function filefield_file_upload_process in FileField 6.2
The 'process' callback for 'filefield_file_upload' form elements. Called after defining the form and while building it, transforms the barebone element array into a file selection widget.
1 string reference to 'filefield_file_upload_process'
- filefield_elements in ./
filefield.module - Implementation of hook_elements().
File
- ./
filefield.widget.inc, line 86 - FileField: Defines a CCK file field type.
Code
function filefield_file_upload_process($element, $edit, &$form_state, $form) {
// Before the element user gets to do his validation, make sure we do ours.
array_unshift($element['#element_validate'], 'filefield_file_upload_validate');
$field = $element['#field'];
$field_name = $field['field_name'];
$upload_name = $field_name . '_' . $element['#delta'];
$requirements = $element['#upload_requirements'];
// Construct the upload description out of user supplied text,
// maximum upload file size, and (optionally) allowed extensions.
if ($requirements['upload possible'] == FALSE) {
$element[$upload_name] = array(
'#type' => 'markup',
'#value' => t('!errors No new files can be uploaded anymore.', array(
'!errors' => implode(' ', $requirements['messages']),
)),
);
return $element;
}
// Make a list out of the messages if there are too many restrictions.
// Looks better than a concatenated sequence of sentences.
$upload_description = count($requirements['messages']) > 2 ? '<ul><li>' . implode('</li><li>', $requirements['messages']) . '</li></ul>' : implode(' ', $requirements['messages']);
$element[$upload_name] = array(
'#type' => 'file',
'#title' => t('Attach new file'),
'#description' => $upload_description,
'#weight' => -1,
// Emulate how FAPI normalizes the _FILES array since this won't go through form_builder
'#name' => 'files[' . $upload_name . ']',
);
// User 1 may even upload files with extensions that are not allowed.
// (At least, that's how core's file_validate_extensions() thinks about it.)
// So only add the JavaScript extension check for other users.
global $user;
if ($user->uid != 1) {
$element[$upload_name]['#attributes'] = array(
'accept' => str_replace(' ', '|', trim($field['widget']['file_extensions'])),
);
}
return $element;
}