How to pass a variable to add an if condition on a form
===

I am working with Symfony2.
I have an EMPLOYEE entity(which has a string field 'category' among others) and a CONTRACT entity.

So,here is my problem :

After editing an employee, I can edit a contract for him.

I would like to add the field "salary" in my contract form if the employee belongs to the category == 'worker', and if category = 'CEO', I don't want to display this field.

Here is my ContractType :

<code>

    class ContractType extends AbstractType
     {
        protected $employee;

        function __construct(MyBundle\Entity\Employee $employee = null) {
        $this->employee = $employee;
         }


        public function buildForm(FormBuilder $builder, array $options) {
        $builder
            ->add('contract_type');

            if ($this->employee !== null && $this->employee->getCategory() == 'worker') 
            {
                $builder
               ->add('salary', 'money', array('currency' => 'USD', 'required' =>false));                            
            }

            elseif ($this->employee !== null && $this->employee->getCategory() == 'CEO') 
            {
                $builder->add('salary', 'hidden', array('required' => false));
                   
            }
        }
    }

</code>

Here's my contract_form.html.twig :

<code>

     {% if employee.category == 'worker'%}
       <tr>
	    <td>{{ form_label(form.salary, "Salary : ") }}</td>
	    <td>{{ form_widget(form.salary) }}</td>
       </tr>
     {% endif %}
<br/>

After editing a employee and setting him category=='worker', when I want to edit him a contract, I have the error : 
<code>

       Method "salary" for object "Symfony\Component\Form\FormView" does not exist in MyBundle:Contract:contract_form.html.twig"

</code>


I am stuck with this error, I don't understand what is wrong in my code

Thanks a lot for you help!



    
