Dear Quicksketch!
I implemented the hook filefield_sources_info and a problem (Function name must be a string)
occured in filefield_sources.module at near line 141:
$function = $source['process'];
$element = $function($element, $edit, $form_state, $form); //this is the line 141 where the error occured
The essence of the problem is that $source['process'] gives back an array not a string, because there
are double elements in there:
Array ( [0] => filefield_source_attach_process2 [1] => filefield_source_attach_process )
As you can see the first element represents my new callback and the second represents the old callback function which should not be there.
Thank You for Your precious work!
By the way the full module what I have used was this:
function MYMODULE_filefield_sources_info() {
$source = array();
$source['attach'] = array(
'name' => t('File attach from server directory'),
'label' => t('File attach'),
'description' => t('Select a file from a directory on the server.'),
'process' => 'filefield_source_attach_process2',
'value' => 'filefield_source_attach_value',
'weight' => 3,
);
return $source;
}
function filefield_source_attach_process2($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, // Required for proper theming.
);
$path = _filefield_source_attach_directory($field['widget']);
$options = _filefield_source_attach_options2($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 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 .= '
' . 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;
}
function _filefield_source_attach_options2($path) {
global $user;
$uf = "_cam_u" . $user->uid . "_";
if (!field_file_check_directory($path, FILE_CREATE_DIRECTORY)) {
drupal_set_message(t('Specified file attach path must exist or be writable.'), 'error');
return FALSE;
}
$options = array();
$file_attach = file_scan_directory($path, '.*', array('.', '..', 'CVS', '.svn'), 0, TRUE, 'filename', 0, 0);
if (count($file_attach)) {
$options = array('' => t('-- Select file --'));
foreach ($file_attach as $filename => $fileinfo) {
$filename = basename($filename);
if ( 'sites/default/files/ftp_upload_video' == $path && 0 !== strpos( $filename, $uf ) ) {
continue;
}
$options[$fileinfo->filename] = $fileinfo->basename;
}
}
natcasesort($options);
return $options;
}
Comments
Comment #1
quicksketchThis is because you are double-defining the same FileField Source, "attach". You need to change
$source['attach']to something else. Or, if you wish to modify the existing "attach" source, used hook_filefield_sources_info_alter() instead.Comment #2
quicksketch