mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
CRUD new action
This commit is contained in:
parent
98b491063c
commit
90ffb7cf7a
@ -18,11 +18,50 @@
|
|||||||
namespace Chill\PersonBundle\CRUD\Controller;
|
namespace Chill\PersonBundle\CRUD\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
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
|
* CRUD Controller for entities attached to a Person
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class EntityPersonCRUDController extends CRUDController
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
34
Entity/HasPerson.php
Normal file
34
Entity/HasPerson.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||||
|
* <http://www.champs-libres.coop>, <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\Entity;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface which applies to entities which are associated to a single person
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface HasPerson
|
||||||
|
{
|
||||||
|
public function setPerson(Person $person = null): HasPerson;
|
||||||
|
|
||||||
|
public function getPerson(): ?Person;
|
||||||
|
}
|
1
Resources/views/CRUD/_new_title.html.twig
Normal file
1
Resources/views/CRUD/_new_title.html.twig
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{ ('crud.' ~ crud_name ~ '.title_new')|trans({'%person%': person|chill_entity_render_string }) }}
|
16
Resources/views/CRUD/new.html.twig
Normal file
16
Resources/views/CRUD/new.html.twig
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{% extends '@ChillPerson/layout.html.twig' %}
|
||||||
|
|
||||||
|
{% set person = entity.person %}
|
||||||
|
{% set activeRouteKey = '' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{% embed('@ChillPerson/CRUD/_new_title.html.twig') %}{% endembed %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block personcontent %}
|
||||||
|
{% embed '@ChillMain/CRUD/_new_content.html.twig' %}
|
||||||
|
{% block crud_content_header %}
|
||||||
|
<h1>{{ ('crud.'~crud_name~'.title_new')|trans({'%person%': person|chill_entity_render_string }) }}</h1>
|
||||||
|
{% endblock crud_content_header %}
|
||||||
|
{% endembed %}
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user