Reputation: 934
I have problem with load form as service in Symfony 3.2 i created Custom field as:
class ImageType extends AbstractType
{
private $path;
/**
* ImageType constructor.
*/
public function __construct($path)
{
$this->path = $path;
}
/**
* @return string
*/
public function getParent()
{
return FileType::class;
}
/**
* @return string
*/
public function getName()
{
return 'image';
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'image_name' => ''
));
}
/**
* @param FormView $view
* @param FormInterface $form
* @param array $options
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['image_name'] = $options['image_name'];
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->setAttribute('image_name', $options['image_name'])
->addModelTransformer(new ImageTransformer($this->path));
}
}
and service.yml:
services:
app.form_image_type:
class: AppBundle\Form\Type\ImageType
arguments: ['%upload_directory%']
tags: [form.type]
But when i run code I have error:
2/2 FileLoaderLoadException in FileLoader.php line 118: A "tags" entry must be an array for service "app.form_image_type" in /var/www/exammple.pl/app/config/services.yml. Check your YAML syntax in /var/www/example/app/config/services.yml (which is being imported from "/var/www/example.pl/app/config/config.yml"). 1/2 InvalidArgumentException in YamlFileLoader.php line 270: A "tags" entry must be an array for service "app.form_image_type" in /var/www/example.pl/app/config/services.yml. Check your YAML syntax.
But according for docs, tags are defined properly, so have fixed this issue ?
Upvotes: 1
Views: 869
Reputation: 428
try with this code :
tags:
- { name: form.type }
look at doc with 3.2 version
Upvotes: 3