/** * @Route( * "/update/{id}", * name="diamante_branch_update", * requirements={"id"="\d+"} * ) * @Template("DiamanteDeskBundle:Branch:update.html.twig") * * @param int $id * @return array */ public function updateAction($id) { $branch = $this->get('diamante.branch.service')->getBranch($id); $command = BranchCommand::fromBranch($branch); if ($this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id)) { $branchEmailConfiguration = $this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id); $branchEmailConfigurationCommand = BranchEmailConfigurationCommand::fromBranchEmailConfiguration($branchEmailConfiguration); $command->setBranchEmailConfiguration($branchEmailConfigurationCommand); } try { $form = $this->createForm(new UpdateBranchType(), $command); $result = $this->edit($command, $form, function ($command) use($branch) { $branchId = $this->get('diamante.branch.service')->updateBranch($command); $this->updateBranchEmailConfiguration($command, $branchId); return $branchId; }, $branch); } catch (MethodNotAllowedException $e) { return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id))); } catch (\Exception $e) { $this->container->get('monolog.logger.diamante')->error(sprintf('Branch update failed: %s', $e->getMessage())); $this->addErrorMessage('diamante.desk.branch.messages.save.error'); return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id))); } return $result; }
/** * @Route( * "/update/{id}", * name="diamante_branch_update", * requirements={"id"="\d+"} * ) * @Template("DiamanteDeskBundle:Branch:update.html.twig") * * @param int $id * @return array */ public function updateAction($id) { $branch = $this->get('diamante.branch.service')->getBranch($id); $command = BranchCommand::fromBranch($branch); if ($this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id) !== null) { $branchEmailConfiguration = $this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id); $branchEmailConfigurationCommand = BranchEmailConfigurationCommand::fromBranchEmailConfiguration($branchEmailConfiguration); $command->setBranchEmailConfiguration($branchEmailConfigurationCommand); } try { $form = $this->createForm('diamante_update_branch_form', $command); $result = $this->edit($command, $form, function ($command) use($branch) { $branchId = $this->get('diamante.branch.service')->updateBranch($command); $this->updateBranchEmailConfiguration($command, $branchId); return $branchId; }); } catch (MethodNotAllowedException $e) { return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id))); } catch (\Exception $e) { $this->handleException($e); return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id))); } return $result; }