FileUploadReceiver
trait FileUploadReceiver (View source)
Provides operations for reading and writing uploaded files to/from {see File} dataobject instances.
Allows writing to a parent record with the following relation types:
- has_one
- has_many
- many_many Additionally supports writing directly to the File table not attached to any parent record.
Note that this trait expects to be applied to a {see \SilverStripe\Forms\FormField} class
Traits
Represents a form field which has an Upload() instance and can upload to a folder
Properties
bool | $relationAutoSetting | Flag to automatically determine and save a has_one-relationship on the saved record (e.g. a "Player" has_one "PlayerImage" would trigger saving the ID of newly created file into "PlayerImageID" on the record). |
Methods
Limit allowed file extensions. Empty by default, allowing all extensions.
Limit allowed file extensions by specifying categories of file types.
Returns list of extensions allowed by this field, or an empty array if there is no restriction
Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)
Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data()
Loads the related record values into this field. This can be uploaded in one of three ways:
Retrieves the list of selected file IDs
No description
Gets the foreign class that needs to be created, or 'File' as default if there is no relationship, or it cannot be determined.
Set if relation can be automatically assigned to the underlying dataobject
Check if relation can be automatically assigned to the underlying dataobject
Details
Upload
getUpload()
Retrieves the Upload handler
$this
setUpload(Upload $upload)
Sets the upload handler
$this
setAllowedExtensions(array $rules)
Limit allowed file extensions. Empty by default, allowing all extensions.
To allow files without an extension, use an empty string. See {@link File::$allowed_extensions} to get a good standard set of extensions that are typically not harmful in a webserver context. See {@link setAllowedMaxFileSize()} to limit file size by extension.
$this
setAllowedFileCategories(string $category)
Limit allowed file extensions by specifying categories of file types.
These may be 'image', 'image/supported', 'audio', 'video', 'archive', 'flash', or 'document' See {@link File::$allowed_extensions} for details of allowed extensions for each of these categories
array
getAllowedExtensions()
Returns list of extensions allowed by this field, or an empty array if there is no restriction
Upload_Validator
getValidator()
Get custom validator for this field
$this
setValidator(Upload_Validator $validator)
Set custom validator for this field
$this
setFolderName(string $folderName)
Sets the upload folder name
string
getFolderName()
Gets the upload folder name
$this
setRecord(DataObject $record)
Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)
DataObject
getRecord()
Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data()
$this
setValue(array $value, array|DataObject|SS_List $record = null)
Loads the related record values into this field. This can be uploaded in one of three ways:
- By passing in a list of file IDs in the $value parameter (an array with a single
key 'Files', with the value being the actual array of IDs).
- By passing in an explicit list of File objects in the $record parameter, and leaving $value blank.
- By passing in a dataobject in the $record parameter, from which file objects will be extracting using the field name as the relation field.
Each of these methods will update both the items (list of File objects) and the field value (list of file ID values).
$this
setItems(SS_List $items)
Sets the items assigned to this field as an SS_List of File objects.
Calling setItems will also update the value of this field, as well as updating the internal list of File items.
array
getItemIDs()
Retrieves the list of selected file IDs
Value()
$this
saveInto(DataObjectInterface $record)
string
getRelationAutosetClass(string $default = File::class)
Gets the foreign class that needs to be created, or 'File' as default if there is no relationship, or it cannot be determined.
$this
setRelationAutoSetting(bool $auto)
Set if relation can be automatically assigned to the underlying dataobject
bool
getRelationAutoSetting()
Check if relation can be automatically assigned to the underlying dataobject