Bonjour tout le monde et bonne année ... :-)

Je rencontre un petit problème qui ne doit pas être bien compliqué à résoudre, mais j'ai beau chercher je ne trouve pas de sujet qui corresponde à ce qu'il m'arrive ...

J'ai actuellement un projet avec un formulaire contenant des formulaires imbriqués. Ce formulaire correspond à l'objet "projet", et un formulaire imbriqué à l'objet "Assumptions". La relation entre les objets est : Proj-Assump 1..M

Pour créer un projet je souhaite afficher le formulaire du FormType projet, mais sans afficher les formulaire imbriqués liés au formType Assumption.

Ce qu'il se passe actuellement, c'est que le form_end() dans mon twig affiche du coup mes formulaires imbriqués (vides en plus) et mon form n'est pas valide (je pense que c'est du à ça ?).

Merci de votre aide, je vous fourni un peu de code ... :

Action controller
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public function viewCreateAction()
    {
        $em = $this->getDoctrine()->getManager();
        $request = $this->get('request'); // We get request through the service 
        $project = new Project(); // Create a blank project object
        // We bind Project object to our Form ProjectType
        $form = $this->createForm(new ProjectType($em), $project); 
 
 
        if ('POST' == $request->getMethod()) { // Si on a posté le formulaire
 
            $form->bind($request); // On bind les données du form
            $this->createProjectInformation($form->getData(), $em);
 
            if ($form->isValid()) { // Si le formulaire est valide
 
                // On utilise notre Manager pour gérer la sauvegarde de l'objet
                $this->createProjectInformation($form->getData(), $em);   
            }
        }
 
        $args = array(
            'formProjectInformation' => $form->createView(),
            'confirm' => $this->confirm,
        );
        return $this->render('ATSCapacityPlanBundle:Configuration:ConfigurationCreate.html.twig', $args);
    }

Formtype Projet
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace ATS\CapacityPlanBundle\Form\Type;
 
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
 
class ProjectType extends AbstractType
{
    private $manager;
 
    public function __construct(\Doctrine\ORM\EntityManager $manager)
    {
        $this->manager = $manager;
    }
 
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $name = array('label' => 'Project', 'constraints' => array(new NotBlank, new Length(array('min' => 5, 'max' => 100))));
        $builder->add('name', 'text', $name);
        $engagement = array('label' => 'Engagement', 'constraints' => array(new NotBlank, new Length(array('min' => 5, 'max' => 100))));
        $builder->add('engagement', 'text', $engagement);
        $engagementManager = array('label' => 'Engagement Manager', 'constraints' => array(new NotBlank, new Length(array('min' => 5, 'max' => 100))));
        $builder->add('engagementManager', 'text', $engagementManager);
        $projectManager = array('label' => 'Project Manager', 'constraints' => array(new NotBlank, new Length(array('min' => 5, 'max' => 100))));
        $builder->add('projectManager', 'text', $projectManager);
        $startingWeek = array('label' => 'Starting week', 'constraints' => array(new NotBlank, new Length(array('min' =>1, 'max' => 2))));
        $builder->add('startingWeek', 'text', $startingWeek);
        $version = array('label' => 'Version', 'constraints' => array(new NotBlank, new Length(array('min' => 5, 'max' => 15))));
        $builder->add('version', 'text', $version);
        $versionDate = array('label' => 'Version Date', 'constraints' => array(new NotBlank));
        $builder->add('versionDate', 'date', $versionDate);
        $weekConfig = array('label' => 'Week config', 'constraints' => array(new NotBlank, new Length(array('min' =>1, 'max' => 2))));
        $builder->add('weekConfig', 'text', $weekConfig);
        $builder->add('assumptions', 'collection', array(
        // each item in the array will be an "assumption" field
        'type' => new AssumptionType($this->manager),
        'allow_add'    => true,
        // these options are passed to each "email" type
        'options'  => array(
            'required'  => false,
            'data_class' => 'ATS\CapacityPlanBundle\Entity\Assumption'
            ),
        ));
        $submitOptions = array('label' => 'Add the project', 'attr'=>array('class'=>'btn'));
        $builder->add('validate', 'submit', $submitOptions);
    }
 
    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'ATS\CapacityPlanBundle\Entity\Project',
        );
    }
 
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'ATS\CapacityPlanBundle\Entity\Project',
        ));
    }
 
    public function getName()
    {
        return 'Project';
    }
 
}
formType Assumption
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace ATS\CapacityPlanBundle\Form\Type;
 
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use ATS\CapacityPlanBundle\Form\DataTransformer\ProjectToNumberTransformer;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
 
class AssumptionType extends AbstractType
{
    private $manager;
 
    public function __construct(\Doctrine\ORM\EntityManager $manager)
    {
        $this->manager = $manager;
    }
 
    public function buildForm(FormBuilderInterface $builder, array $options)
    {   
        $blankAssumption = array('required'=>false, 'attr'=>array('rows'=>1, 'cols'=>60));
        $builder->add('text', 'textarea', $blankAssumption);
        $project = array(
                // validation message if the data transformer fails
                'invalid_message' => 'That is not a valid project number',
            );
        $builder->add('project', 'hidden', $project);
        $builder->get('project')
            ->addModelTransformer(new ProjectToNumberTransformer($this->manager));
    }
 
    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'ATS\CapacityPlanBundle\Entity\Assumption',
        );
    }
 
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'ATS\CapacityPlanBundle\Entity\Assumption',
        ));
    }
 
    public function getName()
    {
        return 'Assumption';
    }
 
}
Twig
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{% extends "::GeneralTemplate.html.twig" %} 
 
{% block menu %}
    <div id="menubar">
       <ul id="menu">
          <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
          <li class="selected"><a href={{ path('ats_capacity_plan_configuration') }}>Configuration</a></li>
          <li><a href={{ path('ats_capacity_plan_availability') }}>Availability</a></li>
          <li><a href={{ path('ats_capacity_plan_charge') }}>Charge</a></li>
          <li><a href={{ path('ats_capacity_plan_demands') }}>Demands</a></li>
          <li><a href={{ path('ats_capacity_plan_capacitytable') }}>Capacity Table</a></li>
          <li><a href={{ path('ats_capacity_plan_balance') }}>Balance</a></li>
       </ul>
    </div>
{% endblock %}
 
 
 
{% block body %}
    {{ form_start(formProjectInformation) }}
    {{ form_errors(formProjectInformation) }}
        <table>
           <tr>
             <td>{{ form_label(formProjectInformation.name) }}</td>
             <td>{{ form_widget(formProjectInformation.name) }}</td>
           </tr>
           <tr>
             <td>{{ form_label(formProjectInformation.engagement) }}</td>
             <td>{{form_widget(formProjectInformation.engagement) }}</td>
           </tr>
           <tr>
             <td>{{ form_label(formProjectInformation.engagementManager) }}</td>
             <td>{{form_widget(formProjectInformation.engagementManager) }}</td>
           </tr>
           <tr>
             <td>{{ form_label(formProjectInformation.projectManager) }}</td>
             <td>{{form_widget(formProjectInformation.projectManager) }}</td>
           </tr>
           <tr>
             <td>{{ form_label(formProjectInformation.startingWeek) }}</td>
             <td>{{form_widget(formProjectInformation.startingWeek) }}</td>
           </tr>
           <tr>
             <td>{{ form_label(formProjectInformation.version) }}</td>
             <td>{{form_widget(formProjectInformation.version) }}</td>
           </tr>
           <tr>
             <td>{{ form_label(formProjectInformation.versionDate) }}</td>
             <td>{{form_widget(formProjectInformation.versionDate) }}</td>
           </tr>
           <tr>
             <td>{{ form_label(formProjectInformation.weekConfig) }}</td>
             <td>{{form_widget(formProjectInformation.weekConfig) }}</td>
           </tr>
           <tr>
             <td class="lastLigne"></td>
             <td>{{form_widget(formProjectInformation.validate) }}</td>
           </tr>
        </table>
    {{ form_end(formProjectInformation) }}
{% endblock %}
Merci à tous !