I have the following Symfony form field, this is a drop that loads from an object:
->add('measureunit', 'entity', array('label' => 'Measure Unit', 'class' => 'TeamERPBaseBundle:MeasureUnit', 'expanded' => false, 'empty_value' => '', 'multiple' => false, 'property' => 'abreviation' ))
As you can see, I added 'empty_value' => '' and everything works fine. Now, I want to add an additional parameter at the end, to add let say new measure unit . In other words, the drop-down list should display all the contents of my entity, an empty value and another additional option called new measure unit or something that I want to call. Is it possible?
Edit: The entire form type file has the following:
<?php namespace TeamERP\StoresBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class ProductType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name', 'text', array('label'=>'Product name', 'required' => true, 'attr' => array('class' => 'form-control'))) ->add('code', 'text', array('label'=>'Code', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('description', 'text', array('label'=>'Description', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('cost', 'money', array('label'=>'Cost', 'divisor' => 100, 'currency' => 'BWP')) ->add('category', new CategoryType(), array('required' => false)) ->add('measureunit', 'entity', array('label' => 'Measure Unit', 'class' => 'TeamERPBaseBundle:MeasureUnit', 'expanded' => false, 'placeholder' => '', 'multiple' => false, 'property' => 'abreviation' )) ->add('qtyToPurchase', 'number', array('label'=>'Quantity to purchase', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('reorderPoint', 'number', array('label'=>'Reorder point', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('qtyOnSalesOrder', 'number', array('label'=>'Quantity on sales order', 'required' => false, 'attr' => array('class' => 'form-control'))); } public function getName() { return 'product'; } public function finishView(FormView $view, FormInterface $form, array $options) { $new_choice = new ChoiceView(array(), 'add', 'add new');
Error: Compile Error: Declaration of TeamERP\StoresBundle\Form\Type\ProductType::finishView() must be compatible with Symfony\Component\Form\FormTypeInterface::finishView(Symfony\Component\Form\FormView $view, Symfony\Component\Form\FormInterface $form, array $options)
Edit2 Form work file:
<?php namespace TeamERP\StoresBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Extension\Core\View\ChoiceView; class ProductType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name', 'text', array('label'=>'Product name', 'required' => true, 'attr' => array('class' => 'form-control'))) ->add('code', 'text', array('label'=>'Code', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('description', 'text', array('label'=>'Description', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('cost', 'money', array('label'=>'Cost', 'divisor' => 100, 'currency' => 'BWP')) ->add('category', new CategoryType(), array('required' => false)) ->add('measureunit', 'entity', array('label' => 'Measure Unit', 'class' => 'TeamERPBaseBundle:MeasureUnit', 'expanded' => false, 'placeholder' => '', 'multiple' => false, 'property' => 'abreviation' )) ->add('qtyToPurchase', 'number', array('label'=>'Quantity to purchase', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('reorderPoint', 'number', array('label'=>'Reorder point', 'required' => false, 'attr' => array('class' => 'form-control'))) ->add('qtyOnSalesOrder', 'number', array('label'=>'Quantity on sales order', 'required' => false, 'attr' => array('class' => 'form-control'))); } public function getName() { return 'product'; } public function finishView(FormView $view, FormInterface $form, array $options) { $new_choice = new ChoiceView(array(), 'add', 'add new');