From 5d05043034de7234e21c8e121cd0d02c10648e38 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Sun, 4 Feb 2018 17:11:28 +0800 Subject: [PATCH] Redirect ticket form back to customer update path if applicable --- src/Controller/TicketController.php | 18 ++++++++++++++++-- templates/ticket/form.html.twig | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index 751b4170..83cacd49 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -12,6 +12,7 @@ use Doctrine\ORM\Query; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Validator\Validator\ValidatorInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use DateTime; @@ -246,7 +247,7 @@ class TicketController extends BaseController } } - public function updateForm($id) + public function updateForm(Request $req, $id) { $this->denyAccessUnlessGranted('ticket.update', null, 'No access.'); @@ -263,11 +264,24 @@ class TicketController extends BaseController $em = $this->getDoctrine()->getManager(); + $customer = $obj->getCustomer(); + // get parent associations - $params['customer'] = $obj->getCustomer(); + $params['customer'] = $customer; $params['ticket_types'] = TicketType::getCollection(); $params['statuses'] = TicketStatus::getCollection(); $params['other_ticket_type'] = TicketType::OTHER; + $params['redirect_url'] = $this->generateUrl('ticket_list'); + + // set redirect url + if ($customer) + { + $referer = $req->headers->get('referer'); + $cust_update_url = $this->generateUrl('customer_update', ['id' => $customer->getID()], UrlGeneratorInterface::ABSOLUTE_URL); + + if ($referer == $cust_update_url) + $params['redirect_url'] = $cust_update_url; + } $params['obj'] = $obj; diff --git a/templates/ticket/form.html.twig b/templates/ticket/form.html.twig index 823a08a8..3c4d8e22 100644 --- a/templates/ticket/form.html.twig +++ b/templates/ticket/form.html.twig @@ -134,7 +134,7 @@ text: 'Your changes have been saved!', type: 'success', onClose: function() { - window.location.href = "{{ url('ticket_list') }}"; + window.location.href = "{{ redirect_url }}"; } }); }).fail(function(response) {