[wip] work on base person crud controller

This commit is contained in:
Julien Fastré 2019-11-22 13:47:00 +01:00
parent 122aa3a993
commit 1c92f91f30
3 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<?php
/*
* Copyright (C) 2016-2019 Champs-Libres <info@champs-libres.coop>
*
* 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 <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\CRUD\Controller;
use Chill\MainBundle\CRUD\Controller\CRUDController;
/**
* CRUD Controller for entities attached to a Person
*
*/
class EntityPersonCRUDController extends CRUDController
{
}

View File

@ -0,0 +1,67 @@
<?php
/*
* Copyright (C) 2016-2019 Champs-Libres <info@champs-libres.coop>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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 %}