Skip to content

Commit 8d5bf36

Browse files
committed
Added documentation on the use of the FileProcessorFormField.
1 parent fc337ad commit 8d5bf36

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/php/api/form_builder/form_fields.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,43 @@ Example:
520520
ContentLanguageFormField::create()
521521
```
522522

523+
### FileProcessorFormField
524+
525+
The `FileProcessorFormField` is used to upload files to the server via the file processor.
526+
527+
By default, `FileProcessorFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the appropriate array of fileIDs to the `$parameters` array directly, using the object property as the array key.
528+
If `isSingleFileUpload()` is enabled, the value will be added to the data sub-array of the parameters array and the value can be null.
529+
530+
The checks for the correct file size or extension don't take place in the FormField, this must be defined in the `IFileProcessor`.
531+
532+
__The field supports other settings:__
533+
534+
- `bigPreview($bigPreview = true)` and `isBigPreview()` can be used to set and check if the big preview is enabled. The big preview can only be enabled if single file upload is enabled and the file processor only supports images.
535+
- `context(array $context)` and `getContext()` can be used to set and get the context of the file processor.
536+
- `singleFileUpload($singleFileUpload = true)` and `isSingleFileUpload()` can be used to set and check if only one file can be uploaded.
537+
538+
__Example:__
539+
540+
```php
541+
FileProcessorFormField::create('exampleFileID')
542+
->objectType('foo.bar.example')
543+
->label('foo.bar.example.title')
544+
->singleFileUpload()
545+
->bigPreview()
546+
```
547+
548+
__Additional Buttons__
549+
550+
Additional buttons can be added with `addActionButton(string $actionName, string $title, string $template, string $application = 'wcf', ?IFontAwesomeIcon $icon = null)`.
551+
When this button is pressed, the `fileProcessorCustomAction` event is fired, which can be used via JavaScript to perform additional actions.
552+
553+
__Example:__
554+
555+
```ts
556+
document.getElementById('exampleFileID').parentElement.addEventListener('fileProcessorCustomAction', (event) => {
557+
// event.detail is the $actionName
558+
});
559+
```
523560

524561
### `LabelFormField`
525562

0 commit comments

Comments
 (0)