From 1c92f91f30d803ba5ac5d3510272c87b037eacb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 22 Nov 2019 13:47:00 +0100 Subject: [PATCH] [wip] work on base person crud controller --- .../Controller/EntityPersonCRUDController.php | 28 ++++++++ .../OneToOneEntityPersonCRUDController.php | 67 +++++++++++++++++++ Resources/views/CRUD/edit.html.twig | 13 ++++ 3 files changed, 108 insertions(+) create mode 100644 CRUD/Controller/EntityPersonCRUDController.php create mode 100644 CRUD/Controller/OneToOneEntityPersonCRUDController.php create mode 100644 Resources/views/CRUD/edit.html.twig diff --git a/CRUD/Controller/EntityPersonCRUDController.php b/CRUD/Controller/EntityPersonCRUDController.php new file mode 100644 index 000000000..262c8d8d0 --- /dev/null +++ b/CRUD/Controller/EntityPersonCRUDController.php @@ -0,0 +1,28 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\PersonBundle\CRUD\Controller; + +use Chill\MainBundle\CRUD\Controller\CRUDController; + +/** + * CRUD Controller for entities attached to a Person + * + */ +class EntityPersonCRUDController extends CRUDController +{ +} diff --git a/CRUD/Controller/OneToOneEntityPersonCRUDController.php b/CRUD/Controller/OneToOneEntityPersonCRUDController.php new file mode 100644 index 000000000..cc807e777 --- /dev/null +++ b/CRUD/Controller/OneToOneEntityPersonCRUDController.php @@ -0,0 +1,67 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\PersonBundle\CRUD\Controller; + +use Chill\MainBundle\CRUD\Controller\CRUDController; +use Symfony\Component\HttpFoundation\Request; +use Chill\PersonBundle\Entity\Person; + +/** + * Controller for entities attached as one-to-on to a person + * + */ +class OneToOneEntityPersonCRUDController extends CRUDController +{ + protected function getTemplateFor($action, $entity, Request $request) + { + if (!empty($this->crudConfig[$action]['template'])) { + return $this->crudConfig[$action]['template']; + } + + switch ($action) { + case 'new': + return '@ChillPerson/CRUD/new.html.twig'; + case 'edit': + return '@ChillPerson/CRUD/edit.html.twig'; + case 'index': + return '@ChillPerson/CRUD/index.html.twig'; + default: + throw new \LogicException("the view for action $action is not " + . "defined. You should override ".__METHOD__." to add this " + . "action"); + } + } + + protected function getEntity($id, Request $request): ?object + { + $entity = parent::getEntity($id, $request); + + if (NULL === $entity) { + $entity = $this->createEntity($request); + $person = $this->getDoctrine() + ->getManager() + ->getRepository(Person::class) + ->find($id); + + $entity->setPerson($person); + } + + return $entity; + } + +} diff --git a/Resources/views/CRUD/edit.html.twig b/Resources/views/CRUD/edit.html.twig new file mode 100644 index 000000000..08f8a589d --- /dev/null +++ b/Resources/views/CRUD/edit.html.twig @@ -0,0 +1,13 @@ +{% extends '@ChillPerson/layout.html.twig' %} + +{% set person = entity.person %} +{% set activeRouteKey = '' %} + +{% block title %} +{% include('@ChillMain/CRUD/_edit_title.html.twig') %} +{% endblock title %} + +{% block personcontent %} +{% embed '@ChillMain/CRUD/_edit_content.html.twig' %} +{% endembed %} +{% endblock %} \ No newline at end of file