CRUD new action

This commit is contained in:
2019-12-05 22:57:15 +01:00
parent 98b491063c
commit 90ffb7cf7a
4 changed files with 91 additions and 1 deletions

View File

@@ -18,11 +18,50 @@
namespace Chill\PersonBundle\CRUD\Controller;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Chill\PersonBundle\Entity\Person;
/**
* CRUD Controller for entities attached to a Person
*
*/
class EntityPersonCRUDController extends CRUDController
{
protected function createEntity($action, Request $request): object
{
if (FALSE === $request->query->has('person_id')) {
throw $this->createNotFoundException('the person is not set');
}
$entity = parent::createEntity($action, $request);
$person = $this->getDoctrine()
->getRepository(Person::class)
->find($request->query->getInt('person_id'))
;
if (NULL === $person) {
throw $this->createNotFoundException('the person with this id is not found');
}
$entity->setPerson($person);
return $entity;
}
protected function getTemplateFor($action, $entity, Request $request)
{
if ($this->hasCustomTemplate($action, $entity, $request)) {
return $this->getActionConfig($action)['template'];
}
switch ($action) {
case 'new':
return '@ChillPerson/CRUD/new.html.twig';
case 'edit':
return '@ChillPerson/CRUD/edit.html.twig';
default:
return parent::getTemplateFor($action, $entity, $request);
}
}
}