src/Form/DocumentGeneratorPageFormType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\DocumentGeneratorPage;
  4. use App\Entity\DocumentGeneratorPageTemplate;
  5. use App\Repository\DocumentGeneratorPageTemplateRepository;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  11. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. class DocumentGeneratorPageFormType extends AbstractType
  14. {
  15.     private $em;
  16.     
  17.     public function __construct(EntityManagerInterface $em)
  18.     {
  19.         $this->em $em;
  20.     }
  21.     public function buildForm(FormBuilderInterface $builder, array $options)
  22.     {
  23.         $document   $options['document'];
  24.         $pages = (null !== $document) ? $document->getDocumentGeneratorPages() : array();
  25.         foreach ($pages as $page) {
  26.             $builder
  27.                 ->add('libelle_'.$document->getId().'_'.$page->getId(), TextType::class, [
  28.                     'required' => false ,
  29.                     'attr' => array('class' => 'mb-2'),  
  30.                     'label' => 'Libellé',                   
  31.                     'mapped' => false
  32.                 ])  
  33.                 ->add('contenu_'.$document->getId().'_'.$page->getId(), TextareaType::class, [
  34.                     'required' => false ,
  35.                     'attr' => array('class' => 'contenu-contenu mb-2 tinyPageContent''title'=> "Contenu texte, éditeur riche""rows" => 10),  
  36.                     'label' => 'Contenu',                   
  37.                     'mapped' => false
  38.                 ]);
  39.         }    
  40.     }
  41.     public function configureOptions(OptionsResolver $resolver)
  42.     {
  43.         $resolver->setDefaults([
  44.             'data_class' => DocumentGeneratorPage::class,
  45.             'document'   => null,
  46.         ]);
  47.     }
  48. }