Commit 11e9b45d authored by quicksketch's avatar quicksketch

#612502: Allow commas in permitted file extentions.

parent bc70cf03
......@@ -14,12 +14,17 @@
*/
function filefield_widget_settings_form($widget) {
$form = array();
// Convert the extensions list to be a human-friendly comma-separated list.
$extensions = is_string($widget['file_extensions']) ? $widget['file_extensions'] : 'txt';
$extensions = implode(', ', explode(' ', $extensions));
$form['file_extensions'] = array(
'#type' => 'textfield',
'#title' => t('Permitted upload file extensions'),
'#default_value' => is_string($widget['file_extensions']) ? $widget['file_extensions'] : 'txt',
'#default_value' => $extensions,
'#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.'),
'#element_validate' => array('_filefield_widget_settings_extensions_validate'),
'#weight' => 1,
);
......@@ -89,6 +94,14 @@ function filefield_widget_settings_save($widget) {
return array('file_extensions', 'file_path', 'progress_indicator', 'max_filesize_per_file', 'max_filesize_per_node');
}
function _filefield_widget_settings_extensions_validate($element, &$form_state) {
// Remove commas from file extensions.
$value = str_replace(',', ' ', $element['#value']);
$value = array_filter(explode(' ', $value));
$value = implode(' ', $value);
form_set_value($element, $value, $form_state);
}
function _filefield_widget_settings_file_path_validate($element, &$form_state) {
// Strip slashes from the beginning and end of $widget['file_path']
$form_state['values']['file_path'] = trim($form_state['values']['file_path'], '\\/');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment