SilverStripeâ€™s â€œFiles & Imagesâ€ gives images special treatment. When uploaded, they are identified in the database (in the File table) as being of class Image. This information is later used by the system in various ways, including allowing SetWidth and SetHeight to be called from template code on images even though those methods are not available on other file types.
Recently, I encountered a situation where it was necessary to give PDF files special behavior. It was easy to create a class PDF (child of class File) where I could add the desired methods. However, in order to get the uploader code to realize that .pdf files should be marked as class PDF in table File, I needed to edit the core file sapphire/filesystem/Folder.php. Needless to say, it is undesirable to edit core files to make configuration changes like registering a file type.
The thought came to adjust Folder.php so that it maintains an array of file extensions and associated class names (like array(â€˜PDFâ€™=> array(â€˜pdfâ€™), â€˜Imageâ€™ => array(â€˜jpgâ€™, â€˜jpegâ€™, â€˜gifâ€™, â€˜png)) which would be used to identify the appropriate class with which to tag newly uploaded files. File type registration would be done in _config.php files using a syntax something like: File::register_type('pdf', 'PDF').
Does this should like a feature that would be helpful to the community?
Trying to figure out if this would benefit everyone at large, making it worthwhile to submit a patch, or if we're the only ones that need this, so we such just live with editing the core file.