silverstripe/silverstripe-framework — pull request #2926 by tractorcow (2014-03-06 01:52:33+00:00)
Title: API Enhanced the overwriteWarning behaviour to work independently of the replaceFile setting

This should hopefully provide a solution to the issue raised at https://github.com/silverstripe/silverstripe-framework/pull/2920

When we introduced the overwriteWarning option, this field would force replaceFile to true in any situation, even if the default value is set to false (or set to false in user-code).

To acommodate more flexibility in configuration I've enhanced the notification message slightly, so that the message displayed to users when they upload an already existing file differs slightly, depending on whether they have replaceFile set to true or false.

with replaceFile set to true:

![clipboard-1](https://f.cloud.github.com/assets/936064/2341079/b00da556-a4d0-11e3-8276-232bd46c9b77.jpg)

with replaceFile set to false:

![clipboard-2](https://f.cloud.github.com/assets/936064/2341089/de821692-a4d0-11e3-8abd-5d1facf4ced0.jpg)

I've updated the documentation to hopefully better explain how these field options should be configured, and updated the front end usage guidelines.

Unfortunately, in order to maintain backwards compatibility, I've had to introduce an `UploadField.replaceFile` default config. The reason for this introduction is that according to the current behaviour, overwriteWarning is true, and this forces replaceFile to be true on the instance. If I let it inherit the default value from `Upload.replaceFile`, then this would effectively change the current behaviour so that renaming was the default option, instead of replacing. Hopefully, this at least means that there is no behaviour change for those simply upgrading from the previous version.

`Upload.replaceFile` is still in place, but is only useful in cases where the `Upload` class is used as a stand-alone uploader.

Now the default behaviour for UploadField can be easily configured by updating the overwriteWarning and replaceFile configuration keys on UploadField, and also customised on a per-instance basis.