<?php
namespace Aqarmap\Bundle\DiscussionBundle\Form;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
class DiscussionType extends AbstractType
{
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('content', TextareaType::class, [
'attr' => [
'class' => 'discussion-textarea',
'oninvalid' => "setCustomValidity(\"{$this->translator->trans('neighborhoods.discussion.add_question_validations.question_message')}\")",
'oninput' => 'this.setCustomValidity("")',
],
'required' => true,
])
->add('location', ChoiceType::class, [
'required' => true,
'placeholder' => 'layout.locations',
'attr' => [
'oninvalid' => "setCustomValidity(\"{$this->translator->trans('neighborhoods.discussion.add_question_validations.location_message')}\")",
'oninput' => 'this.setCustomValidity("")',
],
'choices' => $options['selectedLocation'],
'data' => $options['selectedLocationId'],
])
->add('category', EntityType::class, [
'required' => true,
'class' => 'AqarmapDiscussionBundle:Category',
'placeholder' => 'neighborhoods.discussion.placeholder.category',
'attr' => [
'oninvalid' => "setCustomValidity(\"{$this->translator->trans('neighborhoods.discussion.add_question_validations.category_message')}\")",
'oninput' => 'this.setCustomValidity("")',
],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => 'Aqarmap\Bundle\DiscussionBundle\Entity\Discussion',
'flatLocations' => [],
'allow_extra_fields' => true,
'selectedLocation' => [],
'selectedLocationId' => null,
]);
}
public function getBlockPrefix(): string
{
return '';
}
}