mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[wip] work on base person crud controller
This commit is contained in:
parent
122aa3a993
commit
1c92f91f30
28
CRUD/Controller/EntityPersonCRUDController.php
Normal file
28
CRUD/Controller/EntityPersonCRUDController.php
Normal 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
|
||||
{
|
||||
}
|
67
CRUD/Controller/OneToOneEntityPersonCRUDController.php
Normal file
67
CRUD/Controller/OneToOneEntityPersonCRUDController.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
13
Resources/views/CRUD/edit.html.twig
Normal file
13
Resources/views/CRUD/edit.html.twig
Normal 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 %}
|
Loading…
x
Reference in New Issue
Block a user