Symfony workflow :: can go through a workflow event listener

I'm not right now if many of you have already tested the symfony workflow component, but I hope some of you have :)

So, I use this component on two objects , and I want the first object to update the second strong> depending on the transition used.

To do this, I use the workflow guard listener in my first object and try to make workflow::apply on my second object (using the second workflow ...) .

The problem is that when creating workflow::can event is dispatched and it tries to apply the new status on my second object ... This is not normal at all, because I just ask if I can apply some transition, and not ask to really apply . at my first facility .

Config

 framework: workflows: request_for_operation: type: 'state_machine' marking_store: type: 'single_state' arguments: - 'status' supports: - AppBundle\Entity\RequestForOperation places: - draft - pending_for_management - in_progress - finished - canceled transitions: request_for_operations: from: draft to: pending_for_management start_rfop_management: from: pending_for_management to: in_progress close: from: in_progress to: finished cancel: from: [pending_for_management, in_progress] to: canceled operation: type: 'state_machine' marking_store: type: 'single_state' arguments: - 'status' supports: - AppBundle\Entity\Operation places: - draft - pending_for_management - in_progress - finished - canceled transitions: validate_operation: from: draft to: pending_for_management start_tracking: from: pending_for_management to: in_progress close: from: in_progress to: finished cancel: from: [pending_for_management, in_progress] to: canceled 

Subscriber

 class RequestForOperationListener implements EventSubscriberInterface { public function __construct( OperationManager $operationManager, UserNotifier $userNotifier ) { $this->operationManager = $operationManager; $this->userNotifier = $userNotifier; } public static function getSubscribedEvents() { return [ 'workflow.request_for_operation.guard.request_for_operations' => ['onRequestForOperations'], 'workflow.request_for_operation.guard.start_rfop_management' => ['onStartRfopManagement'], 'workflow.request_for_operation.guard.close' => ['onClose'], 'workflow.request_for_operation.guard.cancel' => ['onCancel'], ]; } public function onRequestForOperations(GuardEvent $event) { /** @var RequestForOperation $rfop */ $rfop = $event->getSubject(); //get all the operations linked to the rfop $operations = $rfop->getOperations(); foreach ($operations as $operation) { //set the status of the operation to 'pending_for_management' $this->operationManager->applyTransition($operation, 'validate_operation'); //set the status of the sub-operations to 'pending_for_management' foreach ($operation->getChildren() as $subOperation) { $this->operationManager->applyTransition($subOperation, 'validate_operation'); } //get the users (ie: managers) linked to the operation and notify them (by mail or whatever) $this->notifyAssignedUsers($operation->getUsers(), $operation); } } } 
+5
source share

Source: https://habr.com/ru/post/1262297/


All Articles