如何解决奏鸣曲管理员验证,向集合元素添加违规
Symfony 版本:4.4.11 奏鸣曲管理版本:3.73
嗨,
我们有一个 Sonata 管理表单和一个嵌入的集合。管理表单名为 Patient,嵌入的集合为 Visits。
我们需要根据所选患者验证收集项目(访问)。因此,我们在 Patient Admin 中添加了 Validate 方法。
protected function configureFormFields(FormMapper $form)
{
$form->add('visits',CollectionType::class,$options);
}
/**
* @param ErrorElement $errorElement
* @param \App\Entity\Patient $object
*/
public function validate(ErrorElement $errorElement,$object)
{
foreach($object->getVisits() as $index=>$visit)
{
if(!isValidVisit($visit,$object)){
//Here we wish to add the error to that particular visit row.
$row_key = sprintf('[%d].date',$index);
//We have tried visits.[0].[date],visits.0.date,nested with etc. etc.
$errorElement->with('visits')
->with($row_key)
->addViolation('Invalid Visit')
->end();
->end();
}
}
}
以上你可以想象的不起作用,我们得到一个错误。
Could not parse property path "visits.[0]". Unexpected token.
我们尝试了几种组合,但似乎无法获取要添加错误的确切集合元素的属性路径。我们还尝试在集合上将 error_bubbling 设置为 false。
我们如何将错误添加到确切的集合行,以便我们可以将其显示在特定访问行下方?
请注意,我们必须在顶层表单级别(Admin Validate Method)进行验证,因为我们需要根据所选患者进行验证,并对所有行进行求和并指出超出的特定行极限。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。