function filefield_widget_settings in FileField 6.2
Same name and namespace in other branches
- 5.2 filefield.module \filefield_widget_settings()
- 5 filefield.module \filefield_widget_settings()
- 6.3 filefield.module \filefield_widget_settings()
Implementation of CCK's hook_widget_settings().
File
- ./
filefield.module, line 387
Code
function filefield_widget_settings($op, $widget) {
switch ($op) {
case 'form':
$form = array();
$form['file_extensions'] = array(
'#type' => 'textfield',
'#title' => t('Permitted upload file extensions'),
'#default_value' => is_string($widget['file_extensions']) ? $widget['file_extensions'] : 'txt',
'#size' => 64,
'#description' => t('Extensions a user can upload to this field. Separate extensions with a space and do not include the leading dot. Leaving this blank will allow users to upload a file with any extension.'),
);
$form['file_path'] = array(
'#type' => 'textfield',
'#title' => t('File path'),
'#default_value' => is_string($widget['file_path']) ? $widget['file_path'] : '',
'#description' => t('Optional subdirectory within the "%dir" directory where files will be stored. Do not include trailing slash.', array(
'%dir' => variable_get('file_directory_path', 'files'),
)),
'#element_validate' => array(
'_filefield_widget_settings_file_path_validate',
),
);
if (module_exists('token')) {
$form['file_path']['#suffix'] = theme('token_help', 'user');
}
$form['max_filesize'] = array(
'#type' => 'fieldset',
'#title' => t('File size restrictions'),
'#description' => t('Limits for the size of files that a user can upload. Note that these settings only apply to newly uploaded files, whereas existing files are not affected.'),
'#weight' => 3,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['max_filesize']['max_filesize_per_file'] = array(
'#type' => 'textfield',
'#title' => t('Maximum upload size per file'),
'#default_value' => is_string($widget['max_filesize_per_file']) ? $widget['max_filesize_per_file'] : '',
'#description' => t('Specify the size limit that applies to each file separately. Enter a value like "512" (bytes), "80K" (kilobytes) or "50M" (megabytes) in order to restrict the allowed file size. If you leave this this empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes.'),
'#element_validate' => array(
'_filefield_widget_settings_max_filesize_per_file_validate',
),
);
$form['max_filesize']['max_filesize_per_node'] = array(
'#type' => 'textfield',
'#title' => t('Maximum upload size per node'),
'#default_value' => is_string($widget['max_filesize_per_node']) ? $widget['max_filesize_per_node'] : '',
'#description' => t('Specify the total size limit for all files in field on a given node. Enter a value like "512" (bytes), "80K" (kilobytes) or "50M" (megabytes) in order to restrict the total size of a node. Leave this empty if there should be no size restriction.'),
'#element_validate' => array(
'_filefield_widget_settings_max_filesize_per_node_validate',
),
);
$form['file_widgets'] = array(
'#title' => t('File widgets'),
'#description' => t('Control which kinds of files may be uploaded to the edit form for this field, by specifying the widgets that can handle the desired file types. You can also reorder the widgets to specify their priority: the top-most enabled widget always gets to handle the files that it supports, whereas the bottom-most enabled widget only gets to handle them if the file is not supported by any other other one.'),
'#required' => TRUE,
'#weight' => 5,
'#settings_type' => 'widgets',
);
$file_widget_info = _filefield_file_widget_info($widget);
$form['file_widgets'] = _filefield_draggable_settings_table($form['file_widgets'], $file_widget_info, $widget['file_widgets'], 'file_widget_settings');
return $form;
case 'validate':
$valid = FALSE;
foreach ($widget['file_widgets'] as $file_widget_name => $info) {
if ($info['enabled']) {
$valid = TRUE;
break;
}
}
if (!$valid) {
form_set_error('file_widgets', t('At least one type of file widgets must be enabled.'));
}
// Let modules add their own widget specific validations.
$file_widget_info = _filefield_file_widget_info($widget);
foreach ($file_widget_info as $file_widget_name => $info) {
$file_widget_settings = isset($widget['file_widgets'][$file_widget_name]) ? $widget['file_widgets'][$file_widget_name] : array();
module_invoke($info['module'], 'file_widget_settings_' . $info['name'], 'validate', $file_widget_settings);
}
break;
case 'save':
return array(
'file_extensions',
'file_path',
'max_filesize_per_file',
'max_filesize_per_node',
'file_widgets',
);
}
}