<?php
namespace App\Form\Request;
use App\Form\MediaType;
use App\Entity\Request\RequestForm;
use App\Entity\TranslationSpecific;
use Doctrine\Common\Util\ClassUtils;
use App\Entity\Request\RequestStatus;
use App\Form\Request\RequestExtraType;
use Symfony\Component\Form\AbstractType;
use Eo\HoneypotBundle\Form\Type\HoneypotType;
use Symfony\Component\Form\FormBuilderInterface;
use App\Repository\TranslationSpecificRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Validator\Constraints\Image;
use App\Repository\Request\RequestStatusRepository;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
class RequestFormType extends AbstractType
{
public function __construct(
private TranslationSpecificRepository $translationSpecificRepository,
)
{ }
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$step = $options['step'];
if($step != 'change_status'){
$builder
->add('extraFileds', CollectionType::class, [
'entry_type' => RequestExtraType::class,
'label' => false,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'required' => false,
'mapped' => false
])
/* $builder
->add('descriptionForm', TextareaType::class, [
'attr' => [
'class' => 'radius_10 form_for_other'
],
'required' => false,
])
->add('media', MediaType::class, [
'label' => false,
'noTitle' => true,
'mapped' => false,
'required' => false,
'accept_file_type' => 'image/png, image/svg+xml, image/jpeg, image/jpg',
'constraints_file' => [
new Image([
'mimeTypes' => [
'image/png',
'image/svg+xml',
'image/jpeg',
'image/jpg'
],
'mimeTypesMessage' => 'incompatible_file_type',
])
]
])*/
->add('name', null, [
'attr' => [
'class' => 'radius_10'
],
'label' => false,
])
->add('company', null, [
'attr' => [
'class' => 'radius_10'
],
'label' => false,
])
->add('email', null, [
'attr' => [
'class' => 'radius_10'
],
'label' => false
])
->add('telephone', null, [
'attr' => [
'class' => 'radius_10'
],
'label' => false
])
->add('email_honeypot', HoneypotType::class)
/*->add('captcha', CaptchaType::class, [
'bypass_code' => 'asas',
])*/
;
}
if($step == 'change_status') {
$builder
->add('requestStatus', EntityType::class, [
'class' => RequestStatus::class,
'choice_label' => function (RequestStatus $item) use ($options) {
$data = $this->translationSpecificRepository->findOneBy([
'fk' => 'request_status.label',
'language' => $options['language'],
'refId' => $item->getId()
]);
return $data ? $data->getValueText() : null;
},
'query_builder' => function(RequestStatusRepository $repository) {
return $repository
->createQueryBuilder('rs')
->where('rs.isEnable = 1')
->andWhere('rs.deletedAt IS NULL')
;
},
'required' => true,
'multiple' => false,
'placeholder' => "",
'constraints' => [],
'attr' => ['class' => 'search-select2'],
'label' => false
])
;
}
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => RequestForm::class,
'csrf_protection' => false,
'translation_domain' => 'forms',
'step' => null,
'language' => null
]);
}
}