Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small bug in file processing in form handler #399

Open
Dodger77 opened this issue Sep 30, 2024 · 0 comments
Open

Small bug in file processing in form handler #399

Dodger77 opened this issue Sep 30, 2024 · 0 comments

Comments

@Dodger77
Copy link

Q A
Bug? yes
New Feature? no
Bundle Version 2.5.4
Sulu Version 2.5.20
Browser Version n/a

Actual Behavior

In

private function uploadMedia(FormInterface $form, FormConfigurationInterface $configuration): array
there is a bug, that prevents the use of an own upload/attachment field type without the multiple option, so it is necessary to prevent multiple file uploads (e.g. by use of JavaScript).

The part

            if (!\count($formField->getData())) {
                continue;
            }

leads to the error:

count(): Argument #1 ($value) must be of type Countable|array, Symfony\Component\HttpFoundation\File\UploadedFile given

Expected Behavior

I think the intention of the code a few lines later

            if (!\is_array($files)) {
                $files = [$files];
            }

is to generate an array containing a single UploadedFile object. But that cannot be achieved because of the count before.

Steps to Reproduce

Using a custom file upload field type (by overwriting the AttachmentType throughservice decoration or compiler pass) without the multiple option.

Possible Solutions

            if (!$formField->getData() instanceof UploadedFile && !\count($formField->getData())) {
                continue;
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant