deblan.io-murph/src/Form/ProjectType.php

99 lines
2.5 KiB
PHP
Raw Normal View History

2022-04-05 12:05:06 +02:00
<?php
namespace App\Form;
2022-09-06 14:19:29 +02:00
use App\Core\Form\FileManager\FilePickerType;
use App\Core\Form\Type\CollectionType;
2022-04-05 12:05:06 +02:00
use App\Entity\Project;
2022-09-06 14:19:29 +02:00
use App\Form\Type\SimpleMdTextareaType;
2022-04-05 12:05:06 +02:00
use Symfony\Component\Form\AbstractType;
2022-09-06 14:19:29 +02:00
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
2022-04-05 12:05:06 +02:00
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
class ProjectType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add(
'label',
TextType::class,
[
'label' => 'Libellé',
'required' => true,
'attr' => [
],
'constraints' => [
new NotBlank(),
],
]
);
$builder->add(
'status',
ChoiceType::class,
[
'label' => 'Statut',
'required' => true,
'choices' => [
'Brouillon' => Project::DRAFT,
'Publié' => Project::PUBLISHED,
],
'attr' => [
],
'constraints' => [
new NotBlank(),
],
]
);
$builder->add(
'description',
SimpleMdTextareaType::class,
[
'label' => 'Contenu',
'required' => false,
'constraints' => [
],
]
);
2022-09-06 14:19:29 +02:00
$builder->add(
'image',
FilePickerType::class,
[
'label' => 'Image',
'required' => true,
2022-09-06 14:19:29 +02:00
'data_class' => null,
'attr' => [
],
'constraints' => [
new NotBlank(),
2022-09-06 14:19:29 +02:00
],
]
);
2022-04-05 12:05:06 +02:00
$builder->add(
'links',
CollectionType::class,
[
'label' => 'Liens',
'entry_type' => ProjectLinkType::class,
'by_reference' => false,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
]
);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Project::class,
]);
}
}