function asset_import_form in Asset 5.2
Same name and namespace in other branches
- 5 asset_import/asset_import.module \asset_import_form()
- 6 contrib/asset_import/asset_import.module \asset_import_form()
- 6 asset_import/inc/asset_import.admin.inc \asset_import_form()
1 string reference to 'asset_import_form'
- asset_import_menu in contrib/asset_import/asset_import.module
- Implementation of hook_menu().
File
- contrib/asset_import/asset_import.module, line 57
Code
function asset_import_form() {
$form = array();
$dirpath = variable_get('asset_import_path', '');
if (!file_check_directory($dirpath)) {
drupal_set_message(t("You need to configure the import directory on the Asset import module's <a href='!admin-settings-asset_import'>settings page</a>.", array(
'!admin-settings-asset_import' => url('admin/settings/asset_import'),
)), 'error');
return $form;
}
$files = file_scan_directory($dirpath, '.*');
ksort($files);
if ($files) {
$list = asset_directory_options();
$form['parent'] = array(
'#type' => 'select',
'#title' => t('Parent Directory'),
'#default_value' => $form_values['parent'] ? $form_values['parent'] : $_GET['dir'],
'#options' => $list,
);
$form['subdirectory'] = array(
'#type' => 'textfield',
'#title' => t('Create subdirectory'),
'#size' => 13,
'#description' => t('Enter the name of the subdirectory to be created in the chose Parent Directory. Don\'t add a leading or trailing slash. Leave blank to import all files in the Parent Directory.'),
);
$form['copy'] = array(
'#type' => 'checkbox',
'#title' => t('Copy the files instead of moving them'),
'#description' => t('Default behavior is to move the selected files. Check this options if you wish to copy the files instead of moving them. This could be useful for testing the asset module in comparision with the file handling module(s) you are currently using.'),
);
$fields = array(
'filesize',
'title',
'author',
);
foreach ($fields as $field) {
$form['files'][$field][0] = NULL;
}
$filelist = array(
0 => NULL,
);
foreach ($files as $file) {
$info = pathinfo($file->filename);
if ($info && isset($info['extension'])) {
$filelist[] = substr($file->filename, strlen($dirpath) + 1);
$form['files']['filesize'][] = array(
'#type' => 'item',
'#value' => format_size(filesize($file->filename)),
);
$form['files']['title'][] = array(
'#type' => 'textfield',
'#size' => 20,
'#default_value' => basename($file->name),
);
$form['files']['author'][] = array(
'#type' => 'textfield',
'#size' => 20,
);
}
}
unset($filelist[0]);
foreach ($fields as $field) {
$form['files'][$field][0] = NULL;
}
$form['files']['title']['#tree'] = TRUE;
$form['files']['author']['#tree'] = TRUE;
$form['file_list'] = array(
'#type' => 'value',
'#value' => $filelist,
);
$form['import_file'] = array(
'#type' => 'checkboxes',
'#options' => $filelist,
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Import'),
);
}
else {
$form['import_file'] = array(
'#type' => 'item',
'#value' => t('No files were found'),
);
}
return $form;
}