I have a form which is displayed again after it’s saved. Within this form there is a field for coordinates, which is (if not manually edited by the user) updated automatically using the preUpdate lifecycle callback:
/**
* @ORM\preUpdate
*/
public function setUpdatedValue() {
if (!$this->getSomeTrueFalseValue()) {
$this->setCoordinates();
}
}
This works pretty fine. With one exception. After the entity is saved correctly and the form is displayed again, the values of this particular field are not updated ’cause the form is bound before the preUpdate-method is called. How can I force an update on this value?
This is how the action looks now:
$em = $this->getDoctrine()->getEntityManager();
$request = Request::createFromGlobals();
$object = $this->getDoctrine()->getRepository($this->repository)->find($id);
if (!$object) return $this->forward('MyBundle:Controller:nonExistent');
$form = $this->createForm( Factory::create_instance($this->type), $object);
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
$em->persist($object);
$em->flush();
$this->get('session')->setFlash( 'message', 'Saved');
$this->get('session')->setFlash( 'type', 'ok' );
}
}
You can try to recreate the form once the object has been persisted, ie call
after