diff --git a/CHANGELOG.md b/CHANGELOG.md index ba09121..a3361a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/file-symfony-bridge/src/Form/FileTransformer.php b/packages/file-symfony-bridge/src/Form/FileTransformer.php index 72e3844..70163a7 100644 --- a/packages/file-symfony-bridge/src/Form/FileTransformer.php +++ b/packages/file-symfony-bridge/src/Form/FileTransformer.php @@ -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.', @@ -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.',