Created
January 3, 2021 21:42
-
-
Save alpha1125/b089b4cd84860aded120ee572fca8b50 to your computer and use it in GitHub Desktop.
Symfon form edit, child object, problem never passes line 32.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Route("/{projectId<\d+>}", methods={"GET", "POST", "PUT"}, name="edit" ) | |
* @Entity("project", expr="repository.find(projectId)") | |
* @Template | |
* | |
* @param string $projectId | |
* @param EntityManagerInterface $em | |
* @param Request $request | |
* @param ProjectHelper $projectHelper | |
* | |
* @return array | |
* @throws \Exception | |
*/ | |
public function edit( | |
string $projectId, | |
EntityManagerInterface $em, | |
Request $request, | |
ProjectHelper $projectHelper | |
) { | |
$repo = $em->getRepository('App:Project'); | |
$project = $repo->find($projectId); | |
$object = $repo->getDataObject($project); | |
$objectClassName =$this->_fqcnToShortCn($project->getObjectFqcn()); | |
$formTypeName = sprintf("App\Form\%sType", $objectClassName); | |
$form = $this->createForm($formTypeName, $object); | |
$form->handleRequest($request); | |
if ($form->isSubmitted() && $form->isValid()) { | |
$em->persist($object); | |
$em->flush(); | |
$this->addFlash('success', 'Form saved!'); | |
return $this->formSubmitRedirect($form, $request, $project); | |
} | |
$templateLocation = 'project_forms/_form.'.$objectClassName.'.html.twig'; | |
if (!$this->get('twig') | |
->getLoader() | |
->exists($templateLocation)) { | |
$templateLocation = 'project_forms/_form.html.twig'; | |
} | |
$class = get_class($object); | |
return [ | |
'form' => $form->createView(), | |
'formTemplate' => $templateLocation, | |
'project' => $project, | |
'FormName' => $class::NAME_STR." form", | |
'navActive' => 'Forms', | |
'navData' => $projectHelper->navData($project), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment