I have a Entity Question
and form type for editing Question QuestionType
. I can successfull edit one Question. Now i create a link for editing all Questions.
I would like to edit all Questions in one form, how can i handle this? I try to use collections, but i don't know how to map a single question in a form collection and I'm not sure if that's the right approach.
My QuestionType
look like:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$categories = $this->entityManager->getRepository('MyAppBundle:QuestionCategory')->findByIsActive(true);
$builder->add('category', 'entity', array(
'class' => 'MyAppBundle:QuestionCategory',
'choices' => $categories,
'label' => 'category',
'translation_domain' => 'messages',
'multiple' => false,
'empty_value' => 'msg.pleaseSelect',
'expanded' => false))
->add('translations', 'a2lix_translations', array(
'fields' => array(
'text' => array(
'field_type' => 'textarea',
'label' => 'hintText',
'attr' => array('class' => 'rte')
),
'explanation' => array(
'field_type' => 'textarea',
'label' => 'title',
'attr' => array('class' => '')
)
)
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'My\AppBundle\Entity\Question',
));
}
My Controller with action to edit all Questions, look like:
$em = $this->getDoctrine()->getManager();
$questions = $em->getRepository('MyAppBundle:Question')->findAll();
/**
* -- Here is my problem , how can i my $questions into form? ---
**/
$form = $this->createFormBuilder()
->add('questions', 'collection', array(
'type' => new QuestionType() ,
'allow_add' => false,
'allow_delete' => false,
'label' => false)
)
->add('save', 'submit', array('label' => 'Create'))
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
}
return $this->render('MyAppBundle:Question:editAllQuestions.html.twig', array("form" => $form->createView()));
Has anyone a hint or approach?