trait FileUploadReceiver

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 FormField} class

Traits

Represents a form field which has an Upload() instance and can upload to a folder

Properties

boolean $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

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.

$this
setAllowedFileCategories($category)

Limit allowed file extensions by specifying categories of file types.

array
getAllowedExtensions()

Returns list of extensions allowed by this field, or an empty array if there is no restriction

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)

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:

$this
setItems(SS_List $items)

Sets the items assigned to this field as an SS_List of File objects.

getItems()

Retrieves the current list of files

array
getItemIDs()

Retrieves the list of selected file IDs

Value()

No description

$this
saveInto(DataObjectInterface $record)

No description

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

Details

in UploadReceiver at line 60
Upload getUpload()

Retrieves the Upload handler

Return Value

Upload

in UploadReceiver at line 71
$this setUpload(Upload $upload)

Sets the upload handler

Parameters

Upload $upload

Return Value

$this Self reference

in UploadReceiver at line 87
$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.

Parameters

array $rules List of extensions

Return Value

$this

in UploadReceiver at line 103
$this setAllowedFileCategories($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

Parameters

$category

Return Value

$this

in UploadReceiver at line 115
array getAllowedExtensions()

Returns list of extensions allowed by this field, or an empty array if there is no restriction

Return Value

array

in UploadReceiver at line 125
Upload_Validator getValidator()

Get custom validator for this field

Return Value

Upload_Validator

in UploadReceiver at line 136
$this setValidator(Upload_Validator $validator)

Set custom validator for this field

Parameters

Upload_Validator $validator

Return Value

$this

in UploadReceiver at line 148
$this setFolderName(string $folderName)

Sets the upload folder name

Parameters

string $folderName

Return Value

$this

in UploadReceiver at line 159
string getFolderName()

Gets the upload folder name

Return Value

string

at line 72
$this setRecord(DataObject $record)

Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)

Parameters

DataObject $record

Return Value

$this

at line 83
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()

Return Value

DataObject

at line 134
$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).

Parameters

array $value Array of submitted form data, if submitting from a form
array|DataObject|SS_List $record Full source record, either as a DataObject, SS_List of items, or an array of submitted form data

Return Value

$this Self reference

Exceptions

ValidationException

at line 218
$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.

Parameters

SS_List $items

Return Value

$this self reference

at line 228
SS_List|File[] getItems()

Retrieves the current list of files

Return Value

SS_List|File[]

at line 238
array getItemIDs()

Retrieves the list of selected file IDs

Return Value

array

at line 244
Value()

at line 254
$this saveInto(DataObjectInterface $record)

Parameters

DataObjectInterface $record

Return Value

$this

at line 351
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.

Parameters

string $default Default value to return if no value could be calculated

Return Value

string Foreign class name.

at line 375
$this setRelationAutoSetting(bool $auto)

Set if relation can be automatically assigned to the underlying dataobject

Parameters

bool $auto

Return Value

$this

at line 386
bool getRelationAutoSetting()

Check if relation can be automatically assigned to the underlying dataobject

Return Value

bool