From 0d804dd817587d4d2ff4aa05c7cc15769c9b1089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 21 Feb 2022 00:39:02 +0100 Subject: [PATCH] 3party: redirect to parent when child is opened in view mode --- .../Controller/ThirdPartyController.php | 27 +++++++++++++++++++ .../views/ThirdParty/_form.html.twig | 8 +++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php index 6bb3d7b79..0f776d809 100644 --- a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php +++ b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php @@ -117,6 +117,33 @@ final class ThirdPartyController extends CRUDController ); } + /** + * @param $action + * @param Request $request + * @param ThirdParty $entity + * @return Response|null + */ + protected function onPostFetchEntity($action, Request $request, $entity): ?Response + { + if ($action === 'view' && $entity->getParent() instanceof ThirdParty) { + $params = [ + 'id' => $entity->getParent()->getId() + ]; + + if ($request->query->has('returnPath')) { + $params['returnPath'] = $request->query->get('returnPath'); + } + + if ($request->query->has('returnLabel')) { + $params['returnLabel'] = $request->query->get('returnLabel'); + } + + return $this->redirectToRoute('chill_crud_3party_3party_view', $params); + } + + return null; + } + protected function onPostCheckACL($action, Request $request, $entity): ?Response { if ('edit' === $action || 'view' === $action) { diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig index 6b76b5cb0..4827ba19c 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig @@ -23,15 +23,15 @@ {{ form_row(form.contactDataAnonymous) }} {% endif %} +{% if form.address is defined %} + {{ form_row(form.address) }} +{% endif %} + {% if form.activeChildren is defined %}

{{ 'Contacts'|trans }}

{{ form_widget(form.activeChildren) }} {% endif %} -{% if form.address is defined %} - {{ form_row(form.address) }} -{% endif %} - {{ form_row(form.comment) }} {% if form.centers is defined %}