From 965cf83b1036ba71f70edd0eb53a4ded2c97f55f Mon Sep 17 00:00:00 2001 From: nicoknaepen Date: Wed, 2 Apr 2014 12:02:14 +0200 Subject: [PATCH] Issue #2231251 by nico.knaepen: Added flexibility of file upload behaviour for users on upload --- imce.module | 5 +++++ inc/imce.admin.inc | 3 ++- inc/imce.page.inc | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/imce.module b/imce.module index f3dc4bf..973fc0e 100644 --- a/imce.module +++ b/imce.module @@ -5,6 +5,11 @@ * Implements the necessary hooks for the file browser to work properly. */ +/** Flag for letting the user decide to replace the existing file with the new one + * or keep the existing file and renaming the uploaded file + */ +define('IMCE_RENAME_REPLACE', 1001); + /** * Implements hook_menu(). */ diff --git a/inc/imce.admin.inc b/inc/imce.admin.inc index dd4b8b5..c06e8c8 100644 --- a/inc/imce.admin.inc +++ b/inc/imce.admin.inc @@ -91,7 +91,8 @@ function imce_admin_form($form, &$form_state) { '#options' => array( FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'), FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one'), - FILE_EXISTS_REPLACE => t('Replace the existing file with the new one') + FILE_EXISTS_REPLACE => t('Replace the existing file with the new one'), + IMCE_RENAME_REPLACE => t('Let the user decide wich option to choose') ), ); $form['common']['thumb_method'] = array( diff --git a/inc/imce.page.inc b/inc/imce.page.inc index ab52aa7..b3f780b 100644 --- a/inc/imce.page.inc +++ b/inc/imce.page.inc @@ -138,6 +138,20 @@ function imce_upload_form($form, &$form_state, $ref) { '#options' => imce_thumbnail_options($imce['thumbnails']), ); } + $replace = variable_get('imce_settings_replace', FILE_EXISTS_RENAME); + // In case the user can decide, show options + if ($replace == IMCE_RENAME_REPLACE) { + $form['replace'] = array( + '#type' => 'radios', + '#title' => t('Behaviour for existing files'), + '#default_value' => variable_get('imce_settings_replace', FILE_EXISTS_RENAME), + '#options' => array( + FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'), + FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one'), + FILE_EXISTS_REPLACE => t('Replace the existing file with the new one'), + ), + ); + } $form['upload'] = array( '#type' => 'submit', '#value' => t('Upload'), @@ -293,6 +307,10 @@ function imce_upload_submit($form, &$form_state) { //save uploaded file. $replace = variable_get('imce_settings_replace', FILE_EXISTS_RENAME); + // Retrieve the user option when the option is set for the user to decide + if ($replace == IMCE_RENAME_REPLACE) { + $replace = $form_state['values']['replace']; + } if ($file = file_save_upload('imce', $validators, $diruri, $replace)) { //core bug #54223. -- 1.8.5.2 (Apple Git-48)