/** * Creates and processes the edit form for an Entity using its ID * * @param AbstractAdminListConfigurator $configurator The adminlist configurator * @param string $entityId The id of the entity that will be edited * @param null|Request $request * * @throws NotFoundHttpException * @throws AccessDeniedHttpException * * @return Response */ protected function doEditAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request) { /* @var EntityManager $em */ $em = $this->getEntityManager(); $helper = $em->getRepository($configurator->getRepositoryName())->findOneById($entityId); if ($helper === null) { throw new NotFoundHttpException("Entity not found."); } if (!$configurator->canEdit($helper)) { throw new AccessDeniedHttpException('You do not have sufficient rights to access this page.'); } $formType = $configurator->getAdminType($helper); if (!is_object($formType) && is_string($formType)) { $formType = $this->container->get($formType); } $formFqn = get_class($formType); $event = new AdaptSimpleFormEvent($request, $formFqn, $helper, $configurator->getAdminTypeOptions()); $event = $this->container->get('event_dispatcher')->dispatch(Events::ADAPT_SIMPLE_FORM, $event); $tabPane = $event->getTabPane(); $form = $this->createForm($formFqn, $helper, $configurator->getAdminTypeOptions()); if ($request->isMethod('POST')) { if ($tabPane) { $tabPane->bindRequest($request); $form = $tabPane->getForm(); } else { $form->submit($request); } if ($form->isValid()) { $this->container->get('event_dispatcher')->dispatch(AdminListEvents::PRE_EDIT, new AdminListEvent($helper)); $em->persist($helper); $em->flush(); $this->container->get('event_dispatcher')->dispatch(AdminListEvents::POST_EDIT, new AdminListEvent($helper)); $indexUrl = $configurator->getIndexUrl(); return new RedirectResponse($this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array())); } } $configurator->buildItemActions(); $params = array('form' => $form->createView(), 'entity' => $helper, 'adminlistconfigurator' => $configurator); if ($tabPane) { $params = array_merge($params, array('tabPane' => $tabPane)); } return new Response($this->renderView($configurator->getEditTemplate(), $params)); }