suivi/src/Form/ProjectType.php
2022-05-17 22:19:51 +02:00

71 lines
2.1 KiB
PHP

<?php
namespace App\Form;
use App\Entity\Project;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Core\Form\Type\CollectionType;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
class ProjectType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('label')
->add('establishments', null, [
'multiple' => true,
'attr' => [
'size' => 15,
'data-jschoice' => '',
],
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('e')
->addOrderBy('e.name', 'ASC');
},
])
->add('price', NumberType::class, [
'row_attr' => [
'class' => 'col-md-3',
],
'attr' => [
'step' => 0.01,
],
'scale' => 2,
'required' => false,
'html5' => true,
])
->add('description', null, [
'attr' => ['rows' => 7],
])
->add('client', null, [
'attr' => ['rows' => 7],
])
->add('files',
CollectionType::class,
[
'entry_type' => FileType::class,
'by_reference' => false,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'collection_name' => 'files',
'attr' => [
'class' => 'd-ib col-4 pr-2 pl-2',
],
]
)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Project::class,
]);
}
}