Skip to content

Commit 798f895

Browse files
authored
Merge pull request #453 from WoltLab/file-processor-form-field
Document FileProcessorFormField
2 parents 90681fa + 4d71e09 commit 798f895

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/php/api/form_builder/form_fields.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,44 @@ 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('exampleFileIDContainer').addEventListener('fileProcessorCustomAction', (event: CustomEvent<string>) => {
557+
const actionName = event.detail;
558+
// Perform your action
559+
});
560+
```
523561

524562
### `LabelFormField`
525563

0 commit comments

Comments
 (0)