Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed May 22, 2024
1 parent 883d9c6 commit e1d09c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Then, run the Contao install tool to update the database.
- [DcaRelations](docs/DcaRelations.md)
- [DoctrineOrm](docs/DoctrineOrm.md)
- [Form](docs/Form.md)
- [FileUploadNormalizer](docs/FileUploadNormalizer.md)
- [Formatter](docs/Formatter.md)
- [StringParser](docs/StringParser.md)
- [Undo](docs/Undo.md)
Expand Down
35 changes: 35 additions & 0 deletions docs/FileUploadNormalizer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# FileUploadNormalizer

The problem the `FileUploadNormalizer` tries to tackle is that Contao's file uploads in the form generator (`Form.php`)
accesses file uploads from the widget itself and there is no defined API. The built-in upload form field generates a
typical PHP upload array. Some form field widgets return a Contao Dbafs UUID, others just a file path and some even
return multiple values. It's a mess.

It is designed to be used with the `processFormData` hook specifically.

## Usage

```php

use Codefog\HasteBundle\FileUploadNormalizer;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Form;
use Contao\Widget;

#[AsHook('prepareFormData')]
class PrepareFomDataListener
{
public function __construct(private readonly FileUploadNormalizer $fileUploadNormalizer)
{
}

/**
* @param array<Widget> $fields
*/
public function __invoke(array $submitted, array $labels, array $fields, Form $form, array $files): void
{
// You now have an array of normalized files.
$normalizedFiles = $this->fileUploadNormalizer->normalize($files);
}
}
```

0 comments on commit e1d09c7

Please sign in to comment.