[wip] add basic crud init

This commit is contained in:
Julien Fastré 2019-12-03 14:55:03 +01:00
parent 1c92f91f30
commit db06c9bccc

View File

@ -20,6 +20,9 @@ namespace Chill\PersonBundle\CRUD\Controller;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Symfony\Component\HttpFoundation\Request;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Controller for entities attached as one-to-on to a person
@ -47,9 +50,9 @@ class OneToOneEntityPersonCRUDController extends CRUDController
}
}
protected function getEntity($id, Request $request): ?object
protected function getEntity($action, $id, Request $request): ?object
{
$entity = parent::getEntity($id, $request);
$entity = parent::getEntity($action, $id, $request);
if (NULL === $entity) {
$entity = $this->createEntity($request);
@ -63,5 +66,24 @@ class OneToOneEntityPersonCRUDController extends CRUDController
return $entity;
}
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request)
{
$this->getDoctrine()->getManager()->persist($entity);
}
protected function onPostFetchEntity($action, Request $request, $entity): ?Response
{
if (FALSE === $this->getDoctrine()->getManager()->contains($entity)) {
return new RedirectResponse($this->generateRedirectOnCreateRoute($action, $request, $entity));
}
return null;
}
protected function generateRedirectOnCreateRoute($action, Request $request, $entity)
{
throw new BadMethodCallException("not implemtented yet");
}
}