-
Notifications
You must be signed in to change notification settings - Fork 21
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
improve training + uploads images for training, trainer and place #29
Conversation
448feec
to
97d6347
Compare
projects/open-training/packages/Training/config/packages/easy_admin.yaml
Outdated
Show resolved
Hide resolved
projects/open-training/packages/Training/config/packages/easy_admin.yaml
Outdated
Show resolved
Hide resolved
93ac2a7
to
63af801
Compare
*/ | ||
class Trainer | ||
{ | ||
use UploadableImageTrait; | ||
|
||
/** | ||
* @ORM\Id() | ||
* @ORM\GeneratedValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alterphp Hi, I tried to integrate VichUploaderBundle to EAB. It was pain to use and configure manually for each grid and form...
So I've added trait + ConfigPass drop-in support for uploadable images.
- Trait: https://github.com/TomasVotruba/open-project/pull/29/files#diff-7b21ea5c35990439b5c4b3ed87fa8bee
- Config Pass: https://github.com/TomasVotruba/open-project/pull/29/files#diff-9eddc9a2014f594b78076a50a73f9c36
All we need to do is active the config:
services:
OpenTraining\EasyAdmin\ConfigPass\ImagePropertyAutoconfigureConfigPass:
tags:
- { name: 'easyadmin.config_pass', priority: 2 }
And decorate entity with trait and annotation like this line comment.
How useful this could be in EasyAdminExtension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @TomasVotruba !
To me it's too specific : how is it useful when you need many files on the same entity (ex: logo, banner, backgroundImage, etc) ?
As an alternative, here is how I use Vich : an array field to store and persist metadata and a File property to hold the file itself when loaded. It takes 2 properties for each file but I keep more metadata :
// Entity
/**
* @ORM\Column(type="json_array", nullable=true)
*
* @var array
*/
private $banner;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="anim_banner", fileNameProperty="banner[name]", size="banner[size]", mimeType="banner[mimeType]", originalName="banner[originalName]", dimensions="banner[dimensions]")
*
* @var File
*/
private $bannerFile;
In easy_admin config, reference propertyFile
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's related to single-image use only. For more complex needs, custom code is needed. The EasyAdmin way :)
But for single-image, current setup is overkill:
- define properties in entites
- define setters/getters in entities
- activate random property override so the image is loaded - this is big WTF that took me 30 minutes to make work
- configure image for grids - all of them! → figure out what are their names
- configure imageFile for form - all of them! → -||-
- use explicit
fields
, becauseexclude_fields
cannot be used - so the wholeexclude_fields
idea is killed everywhere with image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setup is needed without this ConfigPass. So much unneccesary complexity it hurts my 👀
+parameters:
+ training_grid_fields:
+ - 'name'
+ - { property: 'image', type: 'image', base_path: '%training_image_path%' }
+ - 'perex'
+ - 'description'
+ - 'capacity'
+ - 'price'
+ - 'place'
+ - 'trainer'
easy_admin:
entities:
Training:
label: 'Školení'
class: 'OpenTraining\Training\Entity\Training'
show:
- exclude_fields:
- - terms
+ fields: '%training_grid_fields%'
list:
- exclude_fields:
- - terms
+ fields: '%training_grid_fields%'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but ... doing this way is like moving complexity to an extension bundle, by pushing it a new feature that increases its dependency map (EasyAdminExtensionBundle would now depend on VichUploaderBundle too).
To me, uploadedAt
should be a metadata directly handled (as a \DateTimeImmutable) by VichUploaderBundle itself, as well as size
, mimeType
and dimensions
. So that you don't need need a 3rd property, 2nd persisted one, to deal with an image...
You put every metadata in a Doctrine json_array
column, and then you take advantage of a ConfigPass in the extension bundle. It usable by anybody, even those who needs metadata, not only the raw basic implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No troubles, I'll keep it here
63af801
to
ddcf1ed
Compare
c6d2638
to
68c076c
Compare
See https://symfony.com/doc/master/bundles/EasyAdminBundle/integration/vichuploaderbundle.html