From dff8261731fd3114f79705ad7f1d1d9366997ce0 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Wed, 14 Aug 2019 12:31:21 +0200 Subject: [PATCH] [RFC] Add success flashes before post event --- src/Bundle/Controller/ResourceController.php | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Bundle/Controller/ResourceController.php b/src/Bundle/Controller/ResourceController.php index e0159008f..b994b60eb 100644 --- a/src/Bundle/Controller/ResourceController.php +++ b/src/Bundle/Controller/ResourceController.php @@ -208,14 +208,17 @@ public function createAction(Request $request): Response } $this->repository->add($newResource); + + if ($configuration->isHtmlRequest()) { + $this->flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource); + } + $postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource); if (!$configuration->isHtmlRequest()) { return $this->viewHandler->handle($configuration, View::create($newResource, Response::HTTP_CREATED)); } - $this->flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource); - if ($postEvent->hasResponse()) { return $postEvent->getResponse(); } @@ -289,6 +292,10 @@ public function updateAction(Request $request): Response return $this->redirectHandler->redirectToReferer($configuration); } + if ($configuration->isHtmlRequest()) { + $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource); + } + $postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource); if (!$configuration->isHtmlRequest()) { @@ -297,8 +304,6 @@ public function updateAction(Request $request): Response return $this->viewHandler->handle($configuration, $view); } - $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource); - if ($postEvent->hasResponse()) { return $postEvent->getResponse(); } @@ -370,14 +375,16 @@ public function deleteAction(Request $request): Response return $this->redirectHandler->redirectToReferer($configuration); } + if ($configuration->isHtmlRequest()) { + $this->flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource); + } + $postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource); if (!$configuration->isHtmlRequest()) { return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT)); } - $this->flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource); - if ($postEvent->hasResponse()) { return $postEvent->getResponse(); } @@ -493,6 +500,10 @@ public function applyStateMachineTransitionAction(Request $request): Response return $this->redirectHandler->redirectToReferer($configuration); } + if ($configuration->isHtmlRequest()) { + $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource); + } + $postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource); if (!$configuration->isHtmlRequest()) { @@ -501,8 +512,6 @@ public function applyStateMachineTransitionAction(Request $request): Response return $this->viewHandler->handle($configuration, $view); } - $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource); - if ($postEvent->hasResponse()) { return $postEvent->getResponse(); }