/**
  * Edits an existing entity.
  *
  * @param $bundle
  * @param Request $request
  * @param $entity
  * @param $id
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function updateAction($bundle, Request $request, $entity, $id)
 {
     // set locale
     $entity_locale = $this->getDefaultLocale();
     if (strlen($request->get('locale')) > 0) {
         $entity_locale = $request->get('locale');
     }
     $ah = $this->get('itf.admin_helper');
     $ah->setBundle($bundle);
     // setup reponse
     $response = ControllerResponse::create($this)->setBundle($bundle)->setEntityName($entity)->setTemplate('ITFAdminBundle:Admin:edit.html.twig');
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository($ah->getEntityRepository($entity))->find($id);
     // locale
     $is_translatable = false;
     if (method_exists($entity, 'setTranslatableLocale')) {
         $entity->setTranslatableLocale($entity_locale);
         $em->refresh($entity);
         $is_translatable = true;
     }
     $entity = new \ITF\AdminBundle\Admin\Entity($entity, $this);
     $response->setEntity($entity->getEntity())->setEntityAssoc($entity->getEntityAssociations())->setEntityTranslatable($is_translatable);
     if (!$entity) {
         throw $this->createNotFoundException(sprintf('Unable to find %e entity.', $entity->getName()));
     }
     $deleteForm = $this->createDeleteForm($entity->getName(), $id);
     $form = $this->createActionForm($entity, 'edit');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->setLogging(true);
         $em->persist($entity->getEntity());
         $em->flush();
         $this->setLogging(false);
         // clear
         $em->clear();
         $em->getConnection()->getConfiguration()->setSQLLogger(null);
         gc_collect_cycles();
         // to edit
         if ($form->get('submit_stay')->isClicked()) {
             return $this->redirect($this->generateUrl('admin_edit', array('id' => $id, 'entity' => $entity->getName('strtolower'), 'bundle' => $ah->getBundleNameShort(), 'locale' => $entity_locale)));
         }
         // to list
         return $this->redirect($this->generateUrl('admin_list', array('entity' => $entity->getName('strtolower'), 'bundle' => $ah->getBundleNameShort())));
     }
     $response->setForm($form->createView())->setDeleteForm($deleteForm->createView());
     return $response->createResponse();
 }