First of all, I am sorry if the question title is a bit odd, but I do not know what else to call it...
I have this form class, which I cannot change:
class ItemDetailType extends AbstractType {
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('name', 'text', array(
'label' => 'Název'))
->add('room', 'entity', array(
'class' => 'CvutFitIctCtuIdentityBundle:Room',
'label' => 'Místnost'))
->add('person', 'entity', array(
'class' => 'CvutFitIctCtuIdentityBundle:Person',
'label' => 'Osoba'))
->add('organizationalUnit', 'entity', array(
'class' => 'CvutFitIctCtuIdentityBundle:OrganizationalUnit',
'label' => 'Organizační jednotka'))
;
$builder->setAttribute('attr', array());
if (isset($options['render_submit']) && $options['render_submit'])
$builder
->add('submit', 'submit', array(
'label' => 'Uložit',
'attr' => array('class' => 'btn btn-success')))
->add('reset', 'reset', array(
'label' => 'Zrušit',
'attr' => array('class' => 'btn btn-danger')))
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Cvut\Fit\BiWt2\InventoryBundle\Entity\Item',
'render_submit' => true,
'attr' => array(
'role' => 'form',
'class' => 'form-horizontal'
)
));
}
/**
* @return string
*/
public function getName() {
return 'cvut_fit_biwt2_inventory_form_item';
}
}
But in a template, I have to render only some of the rows (room, person, organizationalUnit and submit), and not render name and reset. This is in the conditions I am obliged to meet, so editing the class is not a valid option.
In controller I create the form like this:
$form = $this->createForm(
new ItemDetailType, $item, array(
'action' => $this->generateUrl('items_detail_form', array('id' => $id)),
'render_submit' => true
)
);
I tried to render only the desired rows this way, but it only makes the go on top of the form and the remaining two are still rendered under them...
{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_row(form.room) }}
{{ form_row(form.person) }}
{{ form_row(form.organizationalUnit) }}
{{ form_row(form.submit) }}
{{ form_end(form) }}
So I am a bit confused now. Is this the correct behavior? If yes, than how do I achieve what I need? The documentation is somewhat brief about this...
Thank you very much!