murph-skeleton/core/Form/Site/NavigationType.php

110 lines
2.8 KiB
PHP
Raw Normal View History

2021-03-24 12:27:07 +01:00
<?php
namespace App\Core\Form\Site;
use App\Core\Entity\Site\Navigation;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
2021-03-24 12:27:07 +01:00
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
2021-05-12 11:56:48 +02:00
use Symfony\Component\Validator\Constraints\NotBlank;
2021-03-24 12:27:07 +01:00
class NavigationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'label',
TextType::class,
[
2021-03-24 16:54:11 +01:00
'label' => 'Label',
2021-03-24 12:27:07 +01:00
'required' => true,
'attr' => [
],
'constraints' => [
new NotBlank(),
],
]
);
$builder->add(
'code',
TextType::class,
[
'label' => 'Code',
'required' => true,
'attr' => [
],
'constraints' => [
new NotBlank(),
],
]
);
$builder->add(
'domain',
TextType::class,
[
2021-03-24 16:54:11 +01:00
'label' => 'Domain',
2021-03-24 12:27:07 +01:00
'required' => true,
'attr' => [
],
'constraints' => [
new NotBlank(),
],
]
);
2021-05-18 13:26:38 +02:00
$builder->add(
'forceDomain',
CheckboxType::class,
[
'label' => 'Force this domain',
'required' => false,
'attr' => [
],
'constraints' => [
],
]
);
2021-05-18 11:07:06 +02:00
$builder->add(
'additionalDomains',
CollectionType::class,
[
'entry_type' => NavigationAdditionalDomainType::class,
'label' => 'Additional domains',
'by_reference' => false,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
]
);
$builder->add(
'locale',
TextType::class,
[
'label' => 'Locale',
'required' => true,
'attr' => [
],
'constraints' => [
new NotBlank(),
new Length(['min' => 2, 'max' => 10]),
],
]
);
2021-03-24 12:27:07 +01:00
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Navigation::class,
]);
}
}