/** * Edits an existing Collection entity. * * @Route("/{id}/update", name="collection_update") * @Method("post") * @Template() */ public function collection_updateAction($id) { $user = $this->container->get('security.context')->getToken()->getUser(); $dm = $this->get('doctrine.odm.mongodb.document_manager'); $dm->getConfiguration()->setDefaultDB($this->getDataBase($user, $dm)); $collection = $dm->getRepository('PlantnetDataBundle:Collection')->findOneBy(array('id' => $id)); if (!$collection) { throw $this->createNotFoundException('Unable to find Collection entity.'); } $editForm = $this->createForm(new CollectionType(), $collection); $deleteForm = $this->createDeleteForm($id); $request = $this->getRequest(); if ('POST' === $request->getMethod()) { $editForm->bind($request); $url = $collection->getUrl(); if (StringHelp::isGoodForUrl($url)) { if ($editForm->isValid()) { $dm->persist($collection); $dm->flush(); $this->get('session')->getFlashBag()->add('msg_success', 'Collection updated'); return $this->redirect($this->generateUrl('collection_edit', array('id' => $id))); } } else { $form->get('url')->addError(new FormError('Illegal characters (allowed \'a-z\', \'0-9\', \'-\', \'_\').')); } } return $this->render('PlantnetDataBundle:Backend\\Collection:collection_edit.html.twig', array('entity' => $collection, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView())); }