* * 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; } }