unclecheese/silverstripe-dropzone

Feature: Alias UploadField methods

Closed this issue · 3 comments

jonom commented

I noticed the ReadMe states:

FileAttachmentField can be used as a replacement for UploadField in the CMS.

But when I swapped out the class I got a couple of errors because this no longer worked:

$uploadField->setAllowedFileCategories('image');
$uploadField->setAllowedMaxFileNumber(1);

Just wondered if it would be easy to alias these function names and redirect them to the equivalent method on FileAttachmentField?

Ah, good catch. I suppose my language is unclear. I think "replacement" refers to the constructor API only. :)

But probably should add that. There really shouldn't be any room for UploadField to outperform this module. The whole point is that it's better.

I'll have a look myself, but are there any other public methods that UploadField offers that are not in FileAttachmentField?

jonom commented

Yes quite a few :) I've tried to highlight the ones that might be more likely to have been used by people:

setTemplateFileButtons
getTemplateFileButtons
setTemplateFileEdit
getTemplateFileEdit
canPreviewFolder
setCanPreviewFolder
getOverwriteWarning
setOverwriteWarning
setRecord
setItems
getItems
getCustomisedItems
getItemIDs
setConfig
getConfig
getAutoUpload
setAutoUpload
getAllowedMaxFileNumber
setAllowedExtensions
setAllowedFileCategories
getAllowedExtensions
setAllowedMaxFileNumber
canUpload
setCanUpload
canAttachExisting
isActive
setCanAttachExisting
getPreviewMaxWidth
setPreviewMaxWidth
getPreviewMaxHeight
setPreviewMaxHeight
getUploadTemplateName
setUploadTemplateName
getDownloadTemplateName
setDownloadTemplateName
getFileEditFields
setFileEditFields
getFileEditActions
setFileEditActions
getFileEditValidator
setFileEditValidator
handleItem
getItemHandler
attach
fileexists
getRelationAutosetClass

But I dunno... might be easier to just change the docs to read something like FileAttachmentField is a more user-friendly alternative to UploadField in the CMS.

Also one thing I noticed looking at the API is that UploadField allows you to edit attached files (change filename and the like) from right within the field. So that could be the one missing feature that make some people want to hang on to UploadField for the time being?

I think you're right that the easier fix is probably to just update the README. There's no compelling reason why this has to follow the same API as UploadField. Thanks for looking into this.