I use VichImageType::class in my form with Symfony3.
It works well but, in my edit form, I don't have a label for the delete checkbox, it displays form.label.delete next to it...
By default, I don't set any label for Delete field :
$builder
->add('imageFile', VichImageType::class, array(
'label' => 'Picture (.jpg or .png)',
'download_link' => false,
'required' => false
))
How can I set it ?
Thanks.
I don't find the solution so I modified it via jQuery...
var vich = $('.vich-image');
var label = vich.find('label');
if (label.length > 0) {
var checkbox = vich.find('input[type=checkbox]').get(0).outerHTML;
label.html(checkbox + 'Delete image ?');
}
Hi @eved42
That form.label.delete should be translated with the "VichUploaderBundle" translation domain as can be seen here: https://github.com/dustin10/VichUploaderBundle/blob/master/Form/Type/VichFileType.php#L82
Being so, you should just need to add a translation for it on a file for the proper translation domain.
Also, this bundle already brings translations for some locales (https://github.com/dustin10/VichUploaderBundle/tree/master/Resources/translations) so that label should already be translated if your locale is one of those.
If your locale is not available you could consider submitting a PR adding support to it. :-)
Hi, thank you for your answer. My locale is "en" and I don't need any translation for my project. I've never used the system of translations, how do I have to make exactly ?
Simply creating the file app/Resources/translations/VichUploaderBundle.en.yml with the content you need should be enough.
The contents of the file should be something as simple as: form.label.delete: 'Delete image ?'.
And don't forget to clear your cache folder after the change.
It doesn't work. I did everything you said.
I cleared cache with the console : php/bin console cache:clear
And I also deleted var/cache folder in order to be sure...
EDIT : Problem solved !
You have to make sure you have translator enabled in your config :
# app/config/config.yml
framework:
translator: ~
I know this is old, but you can also specify when creating the form field.
$builder
->add('imageFile', VichImageType::class, array(
'label' => 'Picture (.jpg or .png)',
'download_link' => false,
'required' => false,
'delete_label' => 'Delete image ?'
))
https://github.com/dustin10/VichUploaderBundle/blob/master/Form/Type/VichImageType.php
I know this is old, but you can also specify when creating the form field.
$builder ->add('imageFile', VichImageType::class, array( 'label' => 'Picture (.jpg or .png)', 'download_link' => false, 'required' => false, 'delete_label' => 'Delete image ?' ))https://github.com/dustin10/VichUploaderBundle/blob/master/Form/Type/VichImageType.php
Even years later it helps !
Most helpful comment
Simply creating the file
app/Resources/translations/VichUploaderBundle.en.ymlwith the content you need should be enough.The contents of the file should be something as simple as:
form.label.delete: 'Delete image ?'.And don't forget to clear your cache folder after the change.