find($taskId); $defaultReturnPath = $this->generateUrl( 'chill_task_single_task_show', [ 'id' => $task->getId(), 'list_params' => $request->query->get('list_params', []), ] ); $task->getCourse() === null ? $defaultTemplate = '@ChillTask/SingleTask/Person/transition.html.twig' : $defaultTemplate = '@ChillTask/SingleTask/AccompanyingCourse/transition.html.twig'; break; default: return new Response( "The type '{$kind}' is not implemented", Response::HTTP_BAD_REQUEST ); } if (null === $task) { throw $this->createNotFoundException("task with id '{$taskId}' and type " . "'{$type}' does not exists"); } $workflow = $registry->get($task); if (!$workflow->can($task, $transition)) { throw $this->createAccessDeniedException('You are not allowed to apply this transition'); } $transitionInstance = array_values( // array_values needed to reset keys (array_filter preserves keys) array_filter( $workflow->getEnabledTransitions($task), static function (Transition $t) use ($transition) { return $t->getName() === $transition; } ) )[0]; $form = $this->createTransitionForm($task); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { if ($workflow->can($task, $transition)) { $workflow->apply($task, $transition); $em->flush(); $this->addFlash('success', $translator->trans('The transition is successfully applied')); } else { $this->addFlash('error', $translator->trans('The transition could not be applied')); } return $this->redirect($defaultReturnPath); } $event = (new UIEvent($kind, $task)) ->setForm($form) ->setTransition($transitionInstance); $eventDispatcher->dispatch(UIEvent::SHOW_TRANSITION_PAGE, $event); if ($event->hasResponse()) { return $event->getResponse(); } // we simply check that the user can see the task. Other ACL checks // should be performed using `guard` events. $this->denyAccessUnlessGranted(TaskVoter::SHOW, $task); return $this->render($defaultTemplate, [ 'task' => $task, 'form' => $form->createView(), 'transition' => $transitionInstance, ]); } /** * @param \Chill\TaskBundle\Controller\AbstractTask $task * * @return \Symfony\Component\Form\FormInterface */ protected function createTransitionForm(AbstractTask $task) { $builder = $this->createFormBuilder($task); $builder->add('submit', SubmitType::class); return $builder->getForm(); } }