Backend\FormWidgets\FileUpload

Overview

FileUpload renders a form file uploader field.

Supported options:

file: label: Some file type: fileupload

Extends

Public Properties

public int $imageWidth

imageWidth for preview

public int $imageHeight

imageHeight for preview

public mixed $fileTypes

fileTypes accepted

public mixed $mimeTypes

mimeTypes accepted

public mixed $maxFilesize

maxFilesize allowed (MB)

public mixed $maxFiles

maxFiles allowed

public string $externalToolbarAppState

Defines a mount point for the editor toolbar. Must include a module name that exports the Vue application and a state element name. Format: stateElementName Only works in Vue applications and form document layouts.

public array $thumbOptions

thumbOptions used for generating thumbnails

public boolean $useCaption

useCaption allows the user to set a caption

public bool $deferredBinding

deferredBinding defers the upload action using a session key

Show inherited public properties

Inherited Public Properties

Protected Properties

protected $defaultAlias

defaultAlias to identify this widget.

protected Backend\Widgets\Form $configFormWidget

configFormWidget is the embedded form for modifying the properties of the selected file.

protected array $modelsToSave

modelsToSave are models that require saving

Show inherited protected properties

Inherited Protected Properties


Public Methods

public getAcceptedFileTypes()

public getAcceptedFileTypes($includeDot = false): string 

getAcceptedFileTypes returns the specified accepted file types, or the default based on the mode. Image mode will return:

  • jpg,jpeg,bmp,png,gif,svg

public getConfigFormWidget()

public getConfigFormWidget(): void

getConfigFormWidget for the instantiated Form widget

public getSaveValue()

public getSaveValue($value): void

getSaveValue processes the postback value for this widget. If the value is omitted from postback data, the form widget will be skipped.

public init()

public init(): void

init the widget, called by the constructor and free from its parameters.

public nearestModelAttribute()

public nearestModelAttribute($attribute): void

public onLoadAttachmentConfig()

public onLoadAttachmentConfig(): void

onLoadAttachmentConfig loads the configuration form for an attachment, allowing title and description to be set

public onRemoveAttachment()

public onRemoveAttachment(): void

onRemoveAttachment removes a file attachment

public onSaveAttachmentConfig()

public onSaveAttachmentConfig(): void

onSaveAttachmentConfig commits the changes of the attachment configuration form

public onSortAttachments()

public onSortAttachments(): void

onSortAttachments sorts file attachments

public onUpload()

public onUpload(): void

onUpload handler for the server-side processing of uploaded files

public render()

public render(): void

render the widget's primary contents.

public resolveModelAttribute()

public resolveModelAttribute(string $attribute): array 

Returns the final model and attribute name of a nested HTML array attribute. Eg: [$model, $attribute] = $this->resolveModelAttribute($this->valueFrom);

Show inherited public methods

Inherited Public Methods

Protected Methods

protected decorateFileAttributes()

protected decorateFileAttributes($file): System\Models\File 

decorateFileAttributes adds the bespoke attributes used internally by this widget. Added attributes are:

  • thumbUrl
  • pathUrl

protected deferPurgedSaveAttributes()

protected deferPurgedSaveAttributes(
    October\Rain\Database\Model $model,
    array $attributesToPurge
): void 

deferPurgedSaveAttributes removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.

protected getCssDimensions()

protected getCssDimensions(): string 

getCssDimensions returns the CSS dimensions for the uploaded image, uses auto where no dimension is provided.

protected getDisplayMode()

protected getDisplayMode(): string 

getDisplayMode for the file upload. Eg: file-multi, image-single, etc

protected getFileList()

protected getFileList(): void

getFileList returns a list of associated files

protected getFileListFromRelation()

protected getFileListFromRelation(): void

getFileListFromRelation loads the file list from the model relation in memory only if the request is not in a postback state

protected getFileRecord()

protected getFileRecord(): System\Models\File|bool 

getFileRecord for this request, returns false if none available

protected getRelationModel()

protected getRelationModel(): Relation 

Returns the model of a relation type, supports nesting via HTML array.

protected getRelationObject()

protected getRelationObject(): Relation 

Returns the value as a relation object from the model, supports nesting via HTML array.

protected getRelationType()

protected getRelationType(): string 

getRelationType returns the value as a relation type from the model, supports nesting via HTML array.

protected getUploadMaxFilesize()

protected getUploadMaxFilesize(): float 

getUploadMaxFilesize returns max upload filesize in MB

protected isRelationTypeSingular()

protected isRelationTypeSingular(): bool 

isRelationTypeSingular checks if the related model is singular.

protected loadAssets()

protected loadAssets(): void

loadAssets adds widget specific asset files. Use $this->addJs() and $this->addCss() to register new assets to include on the page.

protected performSaveOnModel()

protected performSaveOnModel($model, $data, $options = null): void

performSaveOnModel saves complex data against a model inside a database transaction.

protected prepareModelsToSave()

protected prepareModelsToSave(
    October\Rain\Database\Model $model,
    array $saveData
): array 

prepareModelsToSave takes a model and fills it with data from a multidimensional array. If an attribute is found to be a relationship, that relationship is also filled.

$modelsToSave = $this->prepareModelsToSave($model, [...]);

foreach ($modelsToSave as $modelToSave) {
    $modelToSave->save();
}

protected prepareVars()

protected prepareVars(): void

prepareVars for the view data

protected setModelAttributes()

protected setModelAttributes(
    October\Rain\Database\Model $model,
    array $saveData,
    $attrName = ''
): void 

setModelAttributes sets a data collection to a model attributes, relations are also set.

protected shouldGenerateThumb()

protected shouldGenerateThumb(): void

shouldGenerateThumb determines if the resizer should be used

Show inherited protected methods

Inherited Protected Methods