function filefield_source_attach_process in FileField Sources 6
Same name and namespace in other branches
- 7 sources/attach.inc \filefield_source_attach_process()
A #process callback to extend the filefield_widget element type.
1 string reference to 'filefield_source_attach_process'
- filefield_source_attach_info in sources/
attach.inc - Implements hook_filefield_source_info().
File
- sources/
attach.inc, line 118 - A FileField extension to allow use of files within a server directory.
Code
function filefield_source_attach_process($element, $edit, &$form_state, $form) {
$field = content_fields($element['#field_name'], $element['#type_name']);
$instance = $field['widget'];
$settings = $instance;
$element['filefield_attach'] = array(
'#weight' => 100.5,
'#theme' => 'filefield_source_attach_element',
'#filefield_source' => TRUE,
);
$path = _filefield_source_attach_directory($field['widget']);
$options = _filefield_source_attach_options($path);
$description = t('This method may be used to attach files that exceed the file size limit. Files may be attached from the %directory directory on the server, usually uploaded through FTP.', array(
'%directory' => realpath($path),
));
// Error messages.
if ($options === FALSE || empty($settings['filefield_source_attach_path'])) {
$attach_message = t('A file attach directory could not be located.');
$attach_description = t('Please check your settings for the %field field.', array(
'%field' => $instance['label'],
));
}
elseif (!count($options)) {
$attach_message = t('There currently are no files to attach.');
$attach_description = $description;
}
if (isset($attach_message)) {
$element['filefield_attach']['attach_message'] = array(
'#value' => $attach_message,
);
$element['filefield_attach']['#description'] = $attach_description;
}
else {
$validators = $element['#upload_validators'];
if (isset($validators['filefield_validate_size'])) {
unset($validators['filefield_validate_size']);
}
$description .= '<br />' . filefield_sources_element_validation_help($validators);
$element['filefield_attach']['filename'] = array(
'#type' => 'select',
'#options' => $options,
);
$element['filefield_attach']['#description'] = $description;
}
$element['filefield_attach']['attach'] = array(
'#name' => implode('_', $element['#array_parents']) . '_attach',
'#type' => 'submit',
'#value' => isset($attach_message) ? t('Refresh') : t('Attach'),
'#validate' => array(),
'#submit' => array(
'node_form_submit_build_node',
),
'#ahah' => array(
'path' => 'filefield/ahah/' . $element['#type_name'] . '/' . $element['#field_name'] . '/' . $element['#delta'],
'wrapper' => $element['#id'] . '-ahah-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
);
return $element;
}