nineskeletor/src/Form/ChildType.php

101 lines
3.3 KiB
PHP

<?php
namespace App\Form;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
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 Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
class ChildType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$childtype = $options['childtype'];
$builder
->add('submit', SubmitType::class, [
'label' => 'Valider',
'attr' => ['class' => 'btn btn-success'],
])
->add('name', TextType::class, [
'label' => 'Titre',
])
->add('subname', TextareaType::class, [
'label' => 'Sous Titre',
'required' => false,
'attr' => ['rows' => 5],
])
->add('description', CkeditorType::class, [
'config_name' => 'full_config',
'label' => 'Description',
'required' => false,
'config' => [
'height' => '600px',
'filebrowserUploadRoute' => 'app_ckeditor_upload',
],
])
->add('tags', Select2EntityType::class, [
'label' => 'Tags',
'class' => 'App\Entity\Tag',
'multiple' => true,
'remote_route' => 'app_tag_select',
'primary_key' => 'id',
'text_property' => 'id',
'minimum_input_length' => 0,
'page_limit' => 100,
'allow_clear' => true,
'delay' => 250,
'cache' => false,
'cache_timeout' => 60000,
'language' => 'fr',
'placeholder' => 'Selectionner des tags',
]);
if ($childtype->getHavepin()) {
$builder->add('pins', Select2EntityType::class, [
'label' => 'Pins',
'class' => 'App\Entity\Pin',
'multiple' => true,
'remote_route' => 'app_pin_select',
'primary_key' => 'id',
'text_property' => 'name',
'minimum_input_length' => 0,
'page_limit' => 100,
'allow_clear' => true,
'delay' => 250,
'cache' => false,
'cache_timeout' => 60000,
'language' => 'fr',
'placeholder' => 'Selectionner des pins',
]);
}
if ($childtype->getHaveurl()) {
$builder->add('url', TextareaType::class, [
'label' => 'URL',
'required' => false,
'attr' => ['rows' => 3],
]);
}
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'App\Entity\Child',
'mode' => 'string',
'childtype' => 'App\Entity\Childtype',
]);
}
}