function filebrowser_form in Filebrowser 7.4
Same name and namespace in other branches
- 6.2 filebrowser.module \filebrowser_form()
- 7.2 filebrowser.module \filebrowser_form()
- 7.3 filebrowser.module \filebrowser_form()
Implements hook_form(). @inheritdoc
File
- ./
filebrowser.module, line 77
Code
function filebrowser_form(&$node, &$form_state) {
/** @var Object $type */
$type = node_type_get_type($node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#default_value' => !empty($node->title) ? $node->title : '',
'#required' => TRUE,
);
$form['folder_path'] = array(
'#type' => 'textfield',
'#title' => t('The system file path to the directory'),
'#description' => t('This can be an absolute path or should be relative to the Drupal root directory.'),
'#default_value' => isset($node->folder_path) ? $node->folder_path : '',
'#required' => TRUE,
);
if (module_exists('token')) {
$form['token_help'] = array(
'#title' => t('Replacement patterns'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['token_help']['help'] = array(
'#theme' => 'token_tree',
'#token_types' => array(
'node',
),
);
}
// Folder rights
$form['folder_rights'] = array(
'#type' => 'fieldset',
'#title' => t('Folder rights'),
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['folder_rights']['explore_subdirs'] = array(
'#type' => 'checkbox',
'#title' => t('Allow subdirectory listings.'),
'#default_value' => isset($node->folder_rights->explore_subdirs) ? $node->folder_rights->explore_subdirs : '',
);
$form['folder_rights']['download_archive'] = array(
'#type' => 'checkbox',
'#title' => t("Allow folder's files to be downloaded as an archive"),
'#description' => t("Check this if you allow users to download all folder files as an archive."),
'#default_value' => isset($node->folder_rights->download_archive) ? $node->folder_rights->download_archive : '',
);
$form['folder_rights']['create_folders'] = array(
'#type' => 'checkbox',
'#title' => t("Allow folder to be created"),
'#description' => t("Check this if you allow users to create new folders."),
'#default_value' => isset($node->folder_rights->create_folders) ? $node->folder_rights->create_folders : '',
);
$managers = _filebrowser_options(_filebrowser_externals('download_manager_info'));
$form['folder_rights']['download_manager'] = array(
'#type' => 'select',
'#title' => t("Download manager"),
'#description' => t("A download manager will handle the way of download folder files."),
'#default_value' => isset($node->folder_rights->download_manager) ? $node->folder_rights->download_manager : '',
'#options' => $managers,
'#weight' => -7,
);
$form['folder_rights']['force_download'] = array(
'#type' => 'checkbox',
'#title' => t("Force download"),
'#description' => t("If you select this options clicking a file-link will download the file. Leave this option off if you want the file to open in your browser."),
'#default_value' => isset($node->folder_rights->force_download) ? $node->folder_rights->force_download : '',
);
$forbidden_files_default = "descript.ion\nfile.bbs\n*.git\nCSV\n*.svn";
$form['folder_rights']['forbidden_files'] = array(
'#type' => 'textarea',
'#title' => t('Blacklist'),
'#description' => t('List of forbidden files. Use wildcards (*) if you want to exclude specific file extension. Example: *.git will exclude all files with .git extension.'),
'#default_value' => isset($node->folder_rights->forbidden_files) ? $node->folder_rights->forbidden_files : $forbidden_files_default,
);
$form['folder_rights']['filtered_files'] = array(
'#type' => 'textarea',
'#title' => t('Whitelist'),
'#description' => t('List of patterns to filter, one per line, you can use wildcards (ex. *.pdf).'),
'#default_value' => isset($node->folder_rights->filtered_files) ? $node->folder_rights->filtered_files : '',
);
// Folder upload
$form['folder_uploads'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Folder Upload'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['folder_uploads']['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Allow uploads'),
'#description' => t('Allow users to upload files.'),
'#default_value' => isset($node->folder_uploads->enabled) ? $node->folder_uploads->enabled : '',
);
$form['folder_uploads']['allow_overwrite'] = array(
'#type' => 'checkbox',
'#title' => t('Allow overwrites'),
'#description' => t('Allow files to be overwritten.'),
'#default_value' => isset($node->folder_uploads->allow_overwrite) ? $node->folder_uploads->allow_overwrite : '',
);
$form['folder_uploads']['accepted_uploaded_files'] = array(
'#type' => 'textarea',
'#title' => t('Accepted files for uploading'),
'#description' => t('List of file patterns (e.g. *.jpg) accepted for upload. Empty means anything. One pattern per line'),
'#default_value' => isset($node->folder_uploads->accepted_uploaded_files) ? $node->folder_uploads->accepted_uploaded_files : '',
);
// Folder presentation
$form['folder_presentation'] = array(
'#type' => 'fieldset',
'#title' => t('Folder presentation'),
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$presentations = _filebrowser_options(_filebrowser_externals('presentations'));
$form['folder_presentation']['default_view'] = array(
'#type' => 'select',
'#title' => t("Default view"),
'#default_value' => isset($node->folder_presentation->default_view) ? $node->folder_presentation->default_view : '',
'#options' => $presentations,
);
$form['folder_presentation']['encoding'] = array(
'#type' => 'textfield',
'#title' => t('FileSystem encoding'),
'#description' => t('Set here your file system encoding (UTF-8, ISO-8859-15, etc.).'),
'#default_value' => isset($node->folder_presentation->encoding) ? $node->folder_presentation->encoding : 'UTF-8',
'#required' => TRUE,
);
$form['folder_presentation']['hide_extension'] = array(
'#type' => 'checkbox',
'#title' => t('Hide file extensions'),
'#default_value' => isset($node->folder_presentation->hide_extension) ? $node->folder_presentation->hide_extension : '',
);
$columns = _filebrowser_externals('metadata_info');
$form['folder_presentation']['visible_columns'] = array(
'#type' => 'checkboxes',
'#title' => t("Visible columns"),
'#default_value' => _filebrowser_properties_to_checkboxes($node->folder_presentation->visible_columns),
'#options' => _filebrowser_options($columns),
);
$sortable = array();
foreach ($columns as $name => $data) {
if (isset($data['sortable']) && $data['sortable']) {
$sortable[$name] = $data['title'];
}
}
$form['folder_presentation']['default_sort'] = array(
'#type' => 'select',
'#title' => t("Default sort"),
'#default_value' => isset($node->folder_presentation->default_sort) ? $node->folder_presentation->default_sort : '',
'#options' => $sortable,
);
$form['folder_presentation']['default_sort_order'] = array(
'#type' => 'select',
'#title' => t("Default sort order"),
'#default_value' => isset($node->folder_presentation->default_sort_order) ? $node->folder_presentation->default_sort_order : '',
'#options' => array(
'asc' => t('Ascendant'),
'desc' => t('Descendant'),
),
);
// Specific file handlers settings
$handlers = module_implements("filebrowser_handler_info");
if (count($handlers)) {
$form['file_handlers'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => 'File handlers',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
foreach ($handlers as $module) {
$info = module_invoke($module, "filebrowser_handler_info");
$form['file_handlers']["{$module}"] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => $info['description'],
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -6,
);
$default_setting = $node->file_handlers->{$module};
if (!$default_setting) {
$default_setting = (object) array();
}
$settings = module_invoke($module, "filebrowser_handler_settings", $default_setting);
$form['file_handlers']["{$module}"]['enabled_thumbnailer'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled as thumbnailer'),
'#description' => t('Enable this file handler as thumbnailer.'),
'#default_value' => isset($default_setting->enabled_thumbnailer) ? $default_setting->enabled_thumbnailer : FALSE,
);
$form['file_handlers']["{$module}"]['enabled_metadata'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled as metadata provider'),
'#description' => t('Enable this file handler as metadata provider.'),
'#default_value' => isset($default_setting->enabled_metadata) ? $default_setting->enabled_metadata : FALSE,
);
foreach ($settings as $key => $setting) {
$form['file_handlers']["{$module}"][$key] = $setting;
}
}
}
return $form;
}