file_field_widget_process
- Versions
- 7
file_field_widget_process($element, &$form_state, $form)
An element #process callback for the file_generic field type.
Expands the file_generic type to include the description and display fields.
Code
modules/file/file.field.inc, line 597
<?php
function file_field_widget_process($element, &$form_state, $form) {
$item = $element['#value'];
$item['fid'] = $element['fid']['#value'];
$field = field_info_field($element['#field_name']);
$instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
$settings = $instance['widget']['settings'];
$element['#theme'] = 'file_widget';
// Add the display field if enabled.
if (!empty($field['settings']['display_field']) && $item['fid']) {
$element['display'] = array(
'#type' => empty($item['fid']) ? 'hidden' : 'checkbox',
'#title' => t('Include file in display'),
'#value' => isset($item['display']) ? $item['display'] : $field['settings']['display_default'],
'#attributes' => array('class' => array('file-display')),
);
}
else {
$element['display'] = array(
'#type' => 'hidden',
'#value' => '1',
);
}
// Add the description field if enabled.
if (!empty($instance['settings']['description_field']) && $item['fid']) {
$element['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#value' => isset($item['description']) ? $item['description'] : '',
'#type' => variable_get('file_description_type', 'textfield'),
'#maxlength' => variable_get('file_description_length', 128),
'#description' => t('The description may be used as the label of the link to the file.'),
);
}
// Adjust the AJAX settings so that on upload and remove of any individual
// file, the entire group of file fields is updated together.
if ($field['cardinality'] != 1) {
$new_path = preg_replace('/\/\d+\//', '/', $element['remove_button']['#ajax']['path'], 1);
$new_wrapper = preg_replace('/-\d+-/', '-', $element['remove_button']['#ajax']['wrapper'], 1);
foreach (element_children($element) as $key) {
if (isset($element[$key]['#ajax'])) {
$element[$key]['#ajax']['path'] = $new_path;
$element[$key]['#ajax']['wrapper'] = $new_wrapper;
}
}
unset($element['#prefix'], $element['#suffix']);
}
return $element;
}
?>Login or register to post comments 