Skip to content

Commit

Permalink
[RFC] Add success flashes before post event
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Aug 22, 2019
1 parent 5cf9ef9 commit dff8261
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Bundle/Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
}
Expand Down

0 comments on commit dff8261

Please sign in to comment.