VichUploaderBundle icon indicating copy to clipboard operation
VichUploaderBundle copied to clipboard

About UploadableField in a Doctrine Embeddable class

Open welcoMattic opened this issue 6 years ago • 7 comments

Q A
Bug report? yes
Feature request? yes
BC Break report? no
Symfony version 4.0.8
VichUploaderBundle version 1.8.2

Hi, thanks for your work on this bundle! It's really useful.

However, I just handle a non-usual case with @Vich\UploadableField inside a @ORM\Embeddable() class. This class is embedded in some of other classic Entities in my application. Everything, for display, works. But, when I try to edit file (image in my case) in EasyAdmin (1.17.12), properly configured, none of my @Vich\UploadableField properties are updated.

I've debug the bundle, to find why Embeddable properties flagged as UploadableField were not listed as uploadableField in the MetadataReader. The only thing I've found is that this reader cannot understand the Embeddable behaviour, because it's not a Doctrine Metadata Reader. Is there any way to mix JMS\MetadataReader and Doctrine\ClassMetadata to fix this bug, and add support for Embeddable UploadableField properties?

Thanks a lot!

EDIT: may be this bug fix on symfony/maker-bundle can help us to fix the bug: https://github.com/symfony/maker-bundle/pull/164/files#diff-1eecb8f832b5aae76ee86af10e507715

welcoMattic avatar Apr 30 '18 10:04 welcoMattic

See #350

garak avatar Apr 30 '18 11:04 garak

Hi @garak, the #350 is close. That is why I opened a new ticket, with more details about my debug trip.

welcoMattic avatar Apr 30 '18 11:04 welcoMattic

So, did you see #350?

garak avatar Apr 30 '18 12:04 garak

Yes, I read all comments. So, in my case I've 3 Embedded properties that point to my Embeddable class which contains one UploadableField. I can't proxify 3 properties to one. Your trick works only for 1 Embedded property.

So, that is why I opened this issue

welcoMattic avatar Apr 30 '18 13:04 welcoMattic

@garak @dustin10 It's been planned to support Embedded/Embeddable annotation as I see the comment here https://github.com/dustin10/VichUploaderBundle/blob/master/Metadata/Driver/AnnotationDriver.php#L49

welcoMattic avatar May 25 '18 08:05 welcoMattic

What about adding additional option to UploadableField annotation like fileObjectProperty to use it in PropertyAccessor calls, then mapping might look like so:

	/**
	 * @var File
	 *
	 * @ORM\Embedded(class="App\Entity\Embeddable\File")
	 * @Vich\UploadableField(mapping="level_map_image", fileNameProperty="mapImage.name", fileObjectProperty="mapImage.file")
	 */
	private $mapImage;

Arkemlar avatar Jan 18 '19 00:01 Arkemlar

Feel free to propose a PR

garak avatar Jan 18 '19 08:01 garak