mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
d27937f448
Fixed some whitespace git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47725 467b73ca-7a2a-4603-9d3b-597d59a354a9
61 lines
1.8 KiB
PHP
Executable File
61 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage forms
|
|
*/
|
|
|
|
/**
|
|
* EditableFileField
|
|
* Allows a user to add a field that can be used to upload a file
|
|
*/
|
|
class EditableFileField extends EditableFormField {
|
|
|
|
// this needs to be moved.
|
|
static $has_one = array(
|
|
"UploadedFile" => "File"
|
|
);
|
|
|
|
// TODO Interface and properties for these properties
|
|
static $file_size_restrictions = array();
|
|
static $allowed_file_types = array();
|
|
|
|
static $singular_name = 'File field';
|
|
static $plural_names = 'File fields';
|
|
|
|
function ExtraOptions() {
|
|
return parent::ExtraOptions();
|
|
}
|
|
|
|
function getFormField() {
|
|
if( $field = parent::getFormField() )
|
|
return $field;
|
|
return new FileField($this->Name, $this->Title, $this->getField('Default'));
|
|
// TODO We can't use the preview feature because FileIFrameField also shows the "From the file store" functionality
|
|
//return new FileIFrameField( $this->Name, $this->Title, $this->getField('Default') );
|
|
}
|
|
|
|
function getSimpleFormField(){
|
|
return new FileField($this->Name, $this->Title, $this->getField('Default'));
|
|
}
|
|
|
|
function createSubmittedField($data, $submittedForm, $fieldClass = "SubmittedFileField" ) {
|
|
if( !$_FILES[$this->Name] )
|
|
return null;
|
|
|
|
$submittedField = new $fieldClass();
|
|
$submittedField->Title = $this->Title;
|
|
$submittedField->Name = $this->Name;
|
|
$submittedField->ParentID = $submittedForm->ID;
|
|
|
|
// create the file from post data
|
|
$uploadedFile = new File();
|
|
$uploadedFile->set_stat('file_size_restrictions',$this->stat('file_size_restrictions'));
|
|
$uploadedFile->set_stat('allowed_file_types',$this->stat('allowed_file_types'));
|
|
$uploadedFile->loadUploaded( $_FILES[$this->Name] );
|
|
$submittedField->UploadedFileID = $uploadedFile->ID;
|
|
$submittedField->write();
|
|
return $submittedField;
|
|
}
|
|
}
|
|
?>
|