我正在使用symfony 4.3中的工作流组件。对于我的实体,我有一个标记属性和一个transition_contexts属性。 transition_contexts具有JSON类型,例如
[{"time": ..., "context":[all info I want], "new_marking" : "some_place", {etc...}]
进行每个转换。 我还想为称为创建的初始位置设置一个transition_context。现在,当我创建一个新对象时,我的transition_contexts看起来像:
[{"time": ..., "context":[], "new_marking" : "creation"}]
对于所有其他转换,我使用apply()函数来设置上下文数组,但是对于使用初始位置进行初始化,我不知道该怎么做。
我已经了解了侦听器,所以我尝试了
class FicheSyntheseTransitionListener implements EventSubscriberInterface
{
private $security;
private $connection;
public function __construct(Security $security, ManagerRegistry $em)
{
$this->security = $security;
//ManagerRegistry au lieu de EntityManagerInterface car on a plusieurs entityManager
$this->connection = $em->getManager('fichesynthese');
}
public function addRedacteur(Event $event)
{
$context = $event->getContext();
$user = $this->tokenStorage->getToken()->getUser();
if ($user instanceof UserInterface) {
$context['user'] = $user->getUsername();
}
$event->setContext($context);
$this->get('doctrine')->getManager('fichesynthese')->flush();
}
public static function getSubscribedEvents()
{
return [
'workflow.fiche.entered.creation' => ['addRedacteur'],
];
}
}
但是似乎没有考虑到它。有办法实现吗?手动调用设置初始标记的功能? 谢谢