markSignatureAction( $signature, $request, EntityWorkflowStepSignatureVoter::CANCEL, function (EntityWorkflowStepSignature $signature) {$this->signatureStepStateChanger->markSignatureAsCanceled($signature); }, '@ChillMain/WorkflowSignature/cancel.html.twig', ); } #[Route('/{_locale}/main/workflow/signature/{id}/reject', name: 'chill_main_workflow_signature_reject')] public function rejectSignature(EntityWorkflowStepSignature $signature, Request $request): Response { return $this->markSignatureAction( $signature, $request, EntityWorkflowStepSignatureVoter::REJECT, function (EntityWorkflowStepSignature $signature) {$this->signatureStepStateChanger->markSignatureAsRejected($signature); }, '@ChillMain/WorkflowSignature/reject.html.twig', ); } private function markSignatureAction( EntityWorkflowStepSignature $signature, Request $request, string $permissionAttribute, callable $markSignature, string $template, ): Response { if (!$this->security->isGranted($permissionAttribute, $signature)) { throw new AccessDeniedHttpException('not allowed to cancel this signature'); } $form = $this->formFactory->create(); $form->add('confirm', SubmitType::class, ['label' => 'Confirm']); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->entityManager->wrapInTransaction(function () use ($signature, $markSignature) { $markSignature($signature); }); return new RedirectResponse( $this->chillUrlGenerator->returnPathOr('chill_main_workflow_show', ['id' => $signature->getStep()->getEntityWorkflow()->getId()]) ); } return new Response( $this->twig->render( $template, ['form' => $form->createView(), 'signature' => $signature] ) ); } }