src/EventSubscriber/Quote/QuoteRequestResourceSubscriber.php line 76
<?phpnamespace App\EventSubscriber\Quote;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\EventDispatcher\GenericEvent;use Webmozart\Assert\Assert;use App\Entity\Messaging\AdminMessage;use App\Entity\Messaging\Message;use App\Entity\Messaging\Thread;use App\Entity\Quote\QuoteRequest;use App\Entity\Quote\QuoteRequestWorkflowTransition;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use App\Entity\Quote\RequestForQuote;use App\Entity\Quote\RequestForQuoteWorkflowTransition;use Symfony\Component\Workflow\Registry;class QuoteRequestResourceSubscriber implements EventSubscriberInterface{private $request;private $workflows;private $tokenStorage;public function __construct(RequestStack $request, Registry $workflows, TokenStorageInterface $tokenStorage){$this->request = $request->getCurrentRequest();$this->workflows = $workflows;$this->tokenStorage = $tokenStorage;}// public function onSyliusEntityPreRequestMoreInformation(GenericEvent $event)// {// $entity = $event->getSubject();// Assert::isInstanceOf($entity, RequestForQuote::class);// $workflow = $this->workflows->get($entity, 'request_for_quote');// $subject = $this->request->request->get('request_for_quote_request_more_information_transition')['message']['subject'];// $content = $this->request->request->get('request_for_quote_request_more_information_transition')['message']['content'];// $admin = $this->tokenStorage->getToken()->getUser();// if($workflow->can($entity, 'request_more_information')) {// $workflow->apply($entity, 'request_more_information');// $adminMessage = new AdminMessage();// $adminMessage->setSubject($subject);// $adminMessage->setContent($content);// $adminMessage->setAdmin($admin);// $adminMessage->setRecipient($entity->getCustomer()->getEmail());// $message = new Message();// $message->setType('admin');// $message->setAdminMessage($adminMessage);// $thread = new Thread();// $thread->addAdminMessage($adminMessage);// $thread->addMessage($message);// $thread->setType('quote');// $thread->setTitle($subject);// $transition = new RequestForQuoteWorkflowTransition();// $transition->setType('request_more_information');// $transition->setQuote($entity);// $entity->setThread($thread);// $entity->addTransition($transition);// }// }public function onPreProcessTransition(GenericEvent $event){$entity = $event->getSubject();Assert::isInstanceOf($entity, QuoteRequest::class);$workflow = $this->workflows->get($entity, 'quote_request');$data = $this->request->request->all()['quote_request_process_transition'];$content = $data['message']['content'];if ($workflow->can($entity, 'process')) {$workflow->apply($entity, 'process');$adminMessage = new AdminMessage();$adminMessage->setUser($this->tokenStorage->getToken()->getUser());if ($customer = $entity->getCustomer()) {$adminMessage->setCustomer($customer);}$message = new Message();$message->setType('admin');$message->setAdminMessage($adminMessage);$thread = new Thread();$thread->setTitle('Process');$thread->addMessage($message);$transition = new QuoteRequestWorkflowTransition();$transition->setType('process');$transition->setQuote($entity);$transition->setThread($thread);$entity->addTransition($transition);}}public static function getSubscribedEvents(){return ['app.quote_request.pre_process_transition' => 'onPreProcessTransition',];}}