container = $container; } public function buildForm(FormBuilderInterface $builder, array $options) { // Ajout des champs commun à tout les widgets $builder ->add('submit', SubmitType::class, [ 'label' => ('delete' == $options['mode'] ? 'Confirmer la Suppression' : 'Valider'), 'attr' => ('delete' == $options['mode'] ? ['class' => 'btn btn-danger'] : ['class' => 'btn btn-success']), ]) ->add('name', TextType::class, [ 'label' => 'Nom', ]) ->add('height', IntegerType::class, [ 'label' => 'Hauteur du Widget', ]) ->add('border', ChoiceType::class, [ 'label' => 'Afficher les Bords', 'choices' => ['oui' => '1', 'non' => '0'], ]) ->add('autoajust', ChoiceType::class, [ 'label' => 'Ajuster la Hauteur au Contenu', 'choices' => ['oui' => '1', 'non' => '0'], ]) ->add('opened', ChoiceType::class, [ 'label' => "Afficher le corps du widget à l'ouverture", 'choices' => ['oui' => '1', 'non' => '0'], ]) ->add('viewheader', ChoiceType::class, [ 'label' => "Afficher l'Entête", 'choices' => ['oui' => '1', 'non' => '0'], ]) ->add('colorheaderback', TextType::class, [ 'label' => "Couleur de Fond de l'Entête", 'required' => false, 'attr' => ['class' => 'pick-a-color'], ]) ->add('colorheaderfont', TextType::class, [ 'label' => "Couleur du Texte de l'Entête", 'required' => false, 'attr' => ['class' => 'pick-a-color'], ]) ->add('colorbodyback', TextType::class, [ 'label' => 'Couleur de Fond du Corps', 'required' => false, 'attr' => ['class' => 'pick-a-color'], ]) ->add('colorbodyfont', TextType::class, [ 'label' => 'Couleur du Texte du Corps', 'required' => false, 'attr' => ['class' => 'pick-a-color'], ]) ->add('idicon', HiddenType::class, ['mapped' => false, 'data' => $options['idicon']]); foreach ($options['param']['fields'] as $field) { if ('string' == $field['type']) { $builder ->add($field['id'], TextType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), ]); } elseif ('integer' == $field['type']) { $builder ->add($field['id'], IntegerType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), ]); } elseif ('boolean' == $field['type']) { $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'choices' => ['Non' => 0, 'Oui' => 1], ]); } elseif ('desktopmode' == $field['type']) { $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'choices' => ['Très Petit' => '0', 'Petit' => '1', 'Moyen' => '2', 'Grand' => '3', 'Liste' => '4'], ]); } elseif ('modelist' == $field['type']) { $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'choices' => ['Pavet' => '0', 'Liste' => '1'], ]); } elseif ('withbookmark' == $field['type']) { $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'choices' => ['Favoris + Items' => '0', 'Items uniquement' => '1', 'Favoris uniquement' => '2'], ]); } elseif ('itemcategory' == $field['type']) { $id = $field['value']; $categorys = $this->container->get('doctrine.orm.entity_manager')->getRepository("App\Entity\Itemcategory")->findAll(); $choices = []; foreach ($categorys as $category) { $choices[$category->getLabel()] = $category->getId(); } $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $id, 'required' => ('true' == $field['mandatory']), 'choices' => $choices, 'placeholder' => '-- Sélectionnez une catégorie --', ]); } elseif ('alertcategory' == $field['type']) { $id = $field['value']; $categorys = $this->container->get('doctrine.orm.entity_manager')->getRepository("App\Entity\Alertcategory")->findAll(); $choices = []; foreach ($categorys as $category) { $choices[$category->getLabel()] = $category->getId(); } $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $id, 'required' => ('true' == $field['mandatory']), 'choices' => $choices, 'placeholder' => '-- Sélectionnez une catégorie --', ]); } elseif ('appexternal' == $field['type']) { $id = $field['value']; $appexternals = $this->container->get('doctrine.orm.entity_manager')->getRepository("App\Entity\Appexternal")->findAll(); $choices = []; foreach ($appexternals as $appexternal) { $choices[$appexternal->getName()] = $appexternal->getId(); } $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $id, 'required' => ('true' == $field['mandatory']), 'choices' => $choices, 'placeholder' => '-- Sélectionnez une application --', ]); } elseif ('apponly' == $field['type']) { $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'choices' => ['Documents + Tâches' => '0', 'Documents uniquement' => '1', 'Tâches uniquement' => '2'], ]); } elseif ('target' == $field['type']) { $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'choices' => ['Nouvel onglet/fenêtre' => '_blank', 'iFrame' => 'frame', 'Onglet courant' => '_self'], ]); } elseif ('ckeditor' == $field['type']) { $builder ->add($field['id'], CKEditorType::class, [ 'config_name' => 'full_config', 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'config' => ['filebrowserUploadRoute' => 'app_'.$options['access'].'_pagewidget_upload'], ]); } elseif ('clock' == $field['type']) { $builder ->add($field['id'], ChoiceType::class, [ 'label' => $field['label'], 'mapped' => false, 'label_attr' => ['loc' => $field['loc']], 'data' => $field['value'], 'required' => ('true' == $field['mandatory']), 'choices' => ['Analogique' => '0', 'Numérique' => '1'], ]); } } } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => 'App\Entity\Pagewidget', 'param' => [], 'mode' => 'string', 'access' => 'string', 'idicon' => 'string', ]); } }