奏鸣曲管理员验证,向集合元素添加违规

问题描述

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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...