function file_resup_field_widget_process in File Resumable Upload 8
Same name and namespace in other branches
- 7 file_resup.field.inc \file_resup_field_widget_process()
#process callback for the field widget element.
1 string reference to 'file_resup_field_widget_process'
- file_resup_field_widget_form_alter in ./
file_resup.field.inc - Implements hook_field_widget_form_alter().
File
- ./
file_resup.field.inc, line 90 - Written by Henri MEDOT <henri.medot[AT]absyx[DOT]fr> http://www.absyx.fr
Code
function file_resup_field_widget_process($element, &$form_state, $form) {
$path = drupal_get_path('module', 'file_resup');
$max_files = $element['#file_resup_max_files'];
// Get the upload validators and build a new description.
$field = field_widget_field($element, $form_state);
$instance = field_widget_instance($element, $form_state);
$description = $field['cardinality'] == 1 ? field_filter_xss($instance['description']) : '';
$upload_validators = $element['#file_resup_upload_validators'];
$description = theme('file_upload_help', array(
'description' => $description,
'upload_validators' => $upload_validators,
));
// Add the resup element.
$element['resup'] = array(
'#type' => 'hidden',
'#value_callback' => 'file_resup_value',
'#field_name' => $element['#field_name'],
'#field_parents' => $element['#field_parents'],
'#upload_location' => $element['#upload_location'],
'#file_resup_upload_validators' => $upload_validators,
'#attributes' => array(
'class' => array(
'file-resup',
),
'data-upload-name' => $element['upload']['#name'],
'data-upload-button-name' => $element['upload_button']['#name'],
'data-max-filesize' => $upload_validators['file_validate_size'][0],
'data-description' => $description,
'data-url' => url('file_resup/upload/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value']),
'data-drop-message' => $max_files > -1 ? format_plural($max_files, 'Drop a file here or click <em>Browse</em> below.', 'Drop up to @count files here or click <em>Browse</em> below.') : t('Drop files here or click <em>Browse</em> below.'),
),
'#prefix' => '<div class="file-resup-wrapper">',
'#suffix' => '</div>',
'#attached' => array(
'css' => array(
$path . '/file_resup.css',
),
'js' => array(
$path . '/js/resup.min.js',
$path . '/file_resup.js',
array(
'type' => 'setting',
'data' => array(
'file_resup' => array(
'chunk_size' => file_resup_chunksize(),
),
),
),
),
),
);
// Add the extension list as a data attribute.
if (isset($upload_validators['file_validate_extensions'][0])) {
$extension_list = implode(',', array_filter(explode(' ', $upload_validators['file_validate_extensions'][0])));
$element['resup']['#attributes']['data-extensions'] = $extension_list;
}
// Add the maximum number of files as a data attribute.
if ($max_files > -1) {
$element['resup']['#attributes']['data-max-files'] = $max_files;
}
// Add autostart as a data attribute.
if ($instance['settings']['resup_autostart']) {
$element['resup']['#attributes']['data-autostart'] = 'on';
}
$element['upload_button']['#submit'][] = 'file_resup_field_widget_submit';
$element['#pre_render'][] = 'file_resup_field_widget_pre_render';
return $element;
}