silverstripe/sapphire — pull request #1862 by tractorcow (2013-05-09 03:48:52+00:00)
Title: API UploadField functions on new records

Fixes https://github.com/silverstripe/sapphire/issues/1827

This update allows the FileUpload field to work on unsaved dataobjects, meaning that creating content with imagery is no longer a two step task.

3.1 upgrading and uploadfield.md documentation have all been updated.

The field now works well as a front-end utility for allowing user file upload management. This should be great news for creators of sites with lots of user generated content. An example has been added to the uploadfield.md documentation.

Some config options no longer make sense due to the way the module's core behaviour has been changed, and have been removed (replaceExistingFile).

I've fixed quite a few functionality, validation, and CSS issues that have probably always been there, or that have been introduced during development.

UploadField::validate actually validates now.

The fileupload-ui javascript library has been extended further to try to develop a more user friendly experience: No more has_one image fields with multiple image upload, better error messages, and better error recovery.

Configuration functions can now be chained.

setConfig and getConfig were pretty poorly documented and not well defined, so they've been made protected and replaced with proper property getters and setters with more intelligent logic, and of course per-method documentation.

Field works well on javascript-disabled browsers. The field works as a regular uploader and properly generates Image objects on form submission.

Fixes the following additional bugs (or at least, the below bugs were not noted during testing):

- https://github.com/silverstripe/sapphire/issues/1535 - UploadField 'attach from files' is destructive
- https://github.com/silverstripe/sapphire/issues/1506 - [UploadField] make UploadField frontend ready
- https://github.com/silverstripe/sapphire/issues/1504 - [UploadField] broken disable delete/remove on edit
- https://github.com/silverstripe/sapphire/issues/1531 - Edit problem with UploadField and has_many Pictures => Image
- https://github.com/silverstripe/sapphire/issues/1600 - UploadField doesnt autodetect 1:n relation correctly
- https://github.com/silverstripe/sapphire/issues/1606 - Files uploaded during modeladmin "add new" process should create the appropriate relationship.
- https://github.com/silverstripe/sapphire/issues/1531 - Edit problem with UploadField and has_many Pictures => Image
- https://github.com/silverstripe/sapphire/issues/1509 - [UploadField] shortcut for setting allowed file types

Not sure if fixed (but probably not):

- https://github.com/silverstripe/sapphire/issues/1505 - [UploadField] sometimes does not register changes on a file

I think some of the above issues (with has_many Images) were caused by users not correctly extending the Image class with the other end of the relation. This has been better clarified in the documentation.