/**
  * Handle the state changes for a workflow event
  *
  * @param  WorkflowEvent $event Workflow event
  */
 public function onWorkflowEvent(WorkflowEvent $event)
 {
     // Get the workflow specified in the context
     $workflow = $this->workflowManager->getWorkflow($event->getWorkflowName());
     // Get all incomplete instances for the context in this workflow
     $instances = $event->getContext()->getWorkflowInstancesForWorkflow($event->getWorkflowName(), true);
     // Foreach each instance, check for a move
     foreach ($instances as $instance) {
         $state = $workflow->getState($instance->getStateName());
         if (array_key_exists($event->getEventName(), $state->getEvents())) {
             $instance = $state->getEvents()[$event->getEventName()]->getState()->moveTo($event->getContext(), $instance);
             $this->objectManager->flush($instance);
         }
     }
 }
예제 #2
0
 public function testGets()
 {
     $context = new DummyContext();
     $event = new WorkflowEvent($context, 'testflow', 'eventname');
     $this->assertEquals($context, $event->getContext());
     $this->assertEquals('testflow', $event->getWorkflowName());
     $this->assertEquals('eventname', $event->getEventName());
 }