I would like to display images instead of text for the category choice.
At the moment, I have only the page of the image I saved in my database. I'd like to insert the content into an image HTML element :
Is it possible to insert an image tag ? If yes, how ?
This is my code in SearchType.php :
<?php
namespace App\Form;
use App\Entity\BigCity;
use App\Entity\Categories;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class SearchType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('bigcity', EntityType::class, [
'class' => BigCity::class,
'choice_label' => 'name',
])
->add('category', EntityType::class, [
'class' => Categories::class,
'choice_label' => 'image',
'expanded' => 'true',
'multiple' => 'false',
])
->add('save', SubmitType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => null
]);
}
}