-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
A request to revert changes in removing empty file uploads #24546
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
Comments
ping @enumag |
@szymach I am not sure I understand your issue. Can you create a small example project that allows to reproduce it? |
Long story short - we need those empty file fields in order to substitute the empty value with the one recreated from the database. For example, I have an entity with collection of entities that only contain a file field: class Entity
{
/**
* @var FileEntity[]
**/
private $fileCollection;
}
class FileEntity
{
/**
* This contains a \SplFileInfo object created out of the uploaded file,
* not actually persisted. Is used for the file form field.
**/
public $file;
/**
* Path to the copy of the uploaded file, persisted to database.
* Reads data from file and saves a recreated object during post load
**/
public $filePath;
} Now, the only time a value for the After the change in aforementioned pull request, these empty form fields do not exist in the request at all and are completely removed from the form. We cannot substitute the empty values with the ones from the database, so each I hope this makes our predicament a bit more clear. |
This is quite difficult to understand. Can we see the form? The effect of that PR is to replace |
Here are example forms: class GalleryType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('photos', CollectionType::class, [
'label' => false,
'entry_type' => GalleryPhotoType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false
]);
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Gallery::class
]);
}
} class GalleryPhotoType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('image', ImageType::class, [
'label' => 'admin.gallery.photo'
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Photo::class
]);
}
} Edit an existing |
Did you try it with the commit I referenced above? If I understand the issue correctly it should help... Then we just need to add another test case and we're good. |
Well .... it does :) But what happens if you upload multiple files for a single field? Could you end up with a case of |
I think we have two options only: (1) select none file (2) select multiple files, so (at least on a normal behavior) with a single field you'll have |
As far as I know, that is not possible. |
In that case I consider your fix to do the job. Thank you :) |
After some experiments
In this case I believe we want to remove the nulls. So the correct fix in my opinion is to detect whether the array is associative and use array_filter only if it is not. What do you guys think? EDIT: This is what I have in mind: enumag@79a7f8a |
Hey. I will get back to you later this evening with a response, since I will need to do some additional checks on the solution you provided and I do not have the time ATM. |
OK, so I have checked whether your proposal will affect our multiple files upload and it does, unfortunately. We really need these empty values for our bundle to work, otherwise the form fields are removed before we can do anything about it. We may find a workaround for it, but it could also mean rewriting the bundle from scratch or abandoning it altogether, which I would rather avoid, since we have already put a lot of work into it. I understand that the previous behavior did not explicitly state |
The problem is that when you have
Which is wtf, the expected result for the last case is of course an empty array. This was fixed in symfony/form UploadType by removing the null. However this fix was problematic because it:
We might have to revert it for the sake of BC obviously but I'd much rather find some better solution. Can you explain how my last proposal breaks your bundle? |
Well it does what it currently does - it yields an empty array instead of array with |
Replacing |
Hello, sorry for the delay, busy times. It turned out we were simply referring to index |
Good. I'll send a PR later this week. |
… (enumag) This PR was squashed before being merged into the 2.7 branch (closes #24606). Discussion ---------- [HttpFoundation] Fix FileBag issue with associative arrays | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24546 | License | MIT | Doc PR | Commits ------- 8ea2860 [HttpFoundation] Fix FileBag issue with associative arrays
Hello,
The change introduced in #24198 broke our file upload bundle. Our flow looks like this:
The problem we face now is that the form fields are being completely removed from the request and we have no hook for our functionality. Is there a possibility to revert this change? From what I can tell, it does not actually fix anything, but provides an easier way to deal with empty uploads.
The text was updated successfully, but these errors were encountered: