Voici votre URL de partage https://sharemycode.io/c/3031e228c7 (Cliquer pour copier) (Copié)

Nom du fichier : src/Form/PlanetType.php

<?php

namespace App\Form;

use App\Entity\Planet;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;


class PlanetType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name',TextType::class, [
                'constraints' => [
                    new NotBlank(),
                    new Length([
                        'min' => 2,
                        'minMessage' => 'planet.name.min_length',
                    ]),
                ],
            ])
            ->add('description', TextareaType::class, [
                'constraints' => [
                    new NotBlank(),
                    new Length([
                        'min' => 7,
                        'minMessage' => 'planet.description.min_length',
                    ]),
                ],
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Planet::class,
        ]);
    }
}

Informations

Cet extrait a été créé le 24 nov. 2022 à 15:06:41

Cet extrait expire le 24 déc. 2022 à 15:06:41

Langage : php

Logo php

Code ajouté par totalgiraf

Link

Voici votre URL de partage : https://sharemycode.io/c/3031e228c7 Copié