markSignatureAction( $signature, $request, EntityWorkflowStepSignatureVoter::CANCEL, fn (EntityWorkflowStepSignature $signature): string => $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, fn (EntityWorkflowStepSignature $signature): string => $this->signatureStepStateChanger->markSignatureAsRejected($signature), '@ChillMain/WorkflowSignature/reject.html.twig', ); } /** * @param callable(EntityWorkflowStepSignature): string $markSignature * * @throws \Twig\Error\LoaderError * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ 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()) { $expectedStep = $this->entityManager->wrapInTransaction(fn () => $markSignature($signature)); return new RedirectResponse( $this->chillUrlGenerator->forwardReturnPath( 'chill_main_workflow_wait', ['id' => $signature->getStep()->getEntityWorkflow()->getId(), 'expectedStep' => $expectedStep] ) ); } return new Response( $this->twig->render( $template, ['form' => $form->createView(), 'signature' => $signature] ) ); } }