更新 OroCRM 帐户时插入数据
Insert data when updating OroCRM Account
我为Oro账户添加了一个新字段(*级别*字段)和一些授权规则。
当我更新帐户时,对于具有无访问权限的角色的用户,不显示字段级别,但在我提交表单时清除帐户级别的值。
所以我想在每次更新帐户时添加级别。我尝试扩展帐户控制器并使用以下代码更改更新方法:
protected function update(Account $entity = null)
{
if (!$entity) {
$entity = $this->getManager()->createEntity();
}
$authorizationChecker = $this->get('security.authorization_checker');
if (!$authorizationChecker->isGranted('EDIT', new FieldVote($entity, 'level'))) {
$entityFromDB = $this->getManager()->find($entity->getId());
$levelFromDB = $entityFromDB->getLevel();
$entity->setLevel($levelFromDB);
}
return $this->get('oro_form.model.update_handler')->update(
$entity,
$this->get('oro_account.form.account'),
$this->get('translator')->trans('oro.account.controller.account.saved.message'),
$this->get('oro_account.form.handler.account')
);
}
但是,保存的时候,账户级别变成了空白。
谁能帮帮我?我正在使用 OroCRM 2.6.19
谢谢大家!
看起来您过早地分配了值,并且在提交表单时它被覆盖了。
我建议您将逻辑移动到 the doctrine even listener 到 preUpdate
事件,这样它将在表单提交后执行并覆盖表单中的数据。
我为Oro账户添加了一个新字段(*级别*字段)和一些授权规则。 当我更新帐户时,对于具有无访问权限的角色的用户,不显示字段级别,但在我提交表单时清除帐户级别的值。
所以我想在每次更新帐户时添加级别。我尝试扩展帐户控制器并使用以下代码更改更新方法:
protected function update(Account $entity = null)
{
if (!$entity) {
$entity = $this->getManager()->createEntity();
}
$authorizationChecker = $this->get('security.authorization_checker');
if (!$authorizationChecker->isGranted('EDIT', new FieldVote($entity, 'level'))) {
$entityFromDB = $this->getManager()->find($entity->getId());
$levelFromDB = $entityFromDB->getLevel();
$entity->setLevel($levelFromDB);
}
return $this->get('oro_form.model.update_handler')->update(
$entity,
$this->get('oro_account.form.account'),
$this->get('translator')->trans('oro.account.controller.account.saved.message'),
$this->get('oro_account.form.handler.account')
);
}
但是,保存的时候,账户级别变成了空白。
谁能帮帮我?我正在使用 OroCRM 2.6.19
谢谢大家!
看起来您过早地分配了值,并且在提交表单时它被覆盖了。
我建议您将逻辑移动到 the doctrine even listener 到 preUpdate
事件,这样它将在表单提交后执行并覆盖表单中的数据。