/**
  * @Route("/edit/{id}", requirements={"id"="\d+"})
  * @ParamConverter("petition", class="CivixCoreBundle:Poll\Question")
  * @Template("CivixFrontBundle:Petition:edit.html.twig")
  */
 public function editAction(Request $request, Petition $petition)
 {
     if ($petition->getUser() !== $this->getUser() || $petition->getPublishedAt()) {
         throw $this->createNotFoundException();
     }
     $petitionFormClass = $this->getPetitionFormClass();
     $form = $this->createForm(new $petitionFormClass($this->getUser()), new PetitionFormModel($petition));
     if ('POST' === $request->getMethod()) {
         if ($form->submit($request)->isValid()) {
             $petition->setUser($this->getUser());
             $manager = $this->getDoctrine()->getManager();
             /* @var $educationalContext \Civix\FrontBundle\Form\Model\EducationalContext */
             $educationalContext = $form->getData()->getEducationalContext();
             $petition->clearEducationalContext();
             foreach ($educationalContext->getItems() as $item) {
                 if ($item->getImageFile()) {
                     $this->get('vich_uploader.storage')->upload($item);
                 }
                 /**
                  * @var $entity \Civix\CoreBundle\Entity\Poll\EducationalContext
                  */
                 $entity = $item->createEntity();
                 if ($entity) {
                     $entity->setQuestion($petition);
                     $manager->persist($entity);
                 }
             }
             $manager->persist($petition);
             $manager->flush();
             $this->get('session')->getFlashBag()->add('notice', 'The petition has been successfully updated');
             return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_petition_index"));
         }
     }
     return ['form' => $form->createView(), 'petition' => $petition, 'isShowGroupSection' => $this->isShowGroupSections($petition)];
 }