Skip to content

Commit

Permalink
symfony-bridge: Update FileTransformer to deal with situations wher…
Browse files Browse the repository at this point in the history
…e the transformer is installed twice on the same form
  • Loading branch information
priyadi committed Oct 11, 2023
1 parent 730f7ab commit 6fddb2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* filepond: Rename `remove_on_null` to `allow_delete` for consistency with other
form types.
* symfony-bridge: Update `FileTransformer` to deal with situations where the
transformer is installed twice on the same form. For example, if
`FileTypeExtension` is active app-wide.

## 1.6.0

Expand Down
8 changes: 8 additions & 0 deletions packages/file-symfony-bridge/src/Form/FileTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function transform($value): ?File
return null;
}

if ($value instanceof File) {
return $value;
}

if (!$value instanceof FileInterface) {
throw new TransformationFailedException(sprintf(
'Expecting "%s", but getting "%s" instead.',
Expand All @@ -61,6 +65,10 @@ public function reverseTransform(mixed $value): ?FileInterface
return null;
}

if ($value instanceof FileInterface) {
return $value;
}

if (!$value instanceof File) {
throw new TransformationFailedException(sprintf(
'Expecting "%s", but getting "%s" instead.',
Expand Down

0 comments on commit 6fddb2b

Please sign in to comment.