i try to configure EasyAdminBundle with my own ImageType to upload file in my ArticleType.
So i created this service in app\config\services.yml
:
services:
oah_news_form_type_image:
class: OAH\NewsBundle\Form\ImageType
tags: [ { name: form.type, alias: 'oah_news_form_type_image' } ]
and tried to call it in my app\config\config.yml
:
easy_admin:
entities:
Article:
class: OAH\NewsBundle\Entity\Article
form:
fields:
- Titre
- Auteur
- Date
- Categorie
- { property : 'Image', type : oah_news_form_type_image}
but i've the following error and i don't know how to fix it :
The type name specified for the service "oah_news_form_type_image" does not match the actual name. Expected "oah_news_form_type_image", given "oah_newsbundle_image"
my ImageType :
class ImageType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('file', 'file');
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'OAH\NewsBundle\Entity\Image'
));
}
/**
* @return string
*/
public function getName()
{
return 'oah_newsbundle_image';
}
}
Thank you !
It appears your alias name must match your return
from getName()
.
@Flushdrew Have you managed to fix your issue after my comment? Anyway I'll give complete answer here. I asked about symfony version you use, because getName
method was removed in 3.0 and the FormType can be identified by its static class name.
In the 2.7 and below in the FormType
class you have to provide a getName
"announce" method, that will inform other FormTypes that this particular form uses this particular name.
/**
* @return string
*/
public function getName()
{
return 'oah_news_form_type_image';
}
Actually alias: 'oah_news_form_type_image'
in the services.yml
has to match the one in the getName()
You can read more about it here: http://symfony.com/doc/2.7/cookbook/form/create_custom_field_type.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With