SonataAdminBundle - check changes in `preUpdate` hook

后端 未结 2 1928
盖世英雄少女心
盖世英雄少女心 2021-01-12 08:11

Is it possible to check if field was changed on preUpdate hook? I\'m looking for something like preUpdate hasChangedField($fieldName) Doctrine functionality. An

2条回答
  •  自闭症患者
    2021-01-12 09:11

    For me the best approach is this in Sonata Admin:

    $newField = $this->getForm()->get('field')->getData();
    $oldField = $this->getForm()->get('field')->getConfig()->getData();
    

    You shouldn't use unit of work unless there is no option. Also, if you have a not mapped field, you can't access it by entity object.

    In a normal Doctrine lyfe cycle event, the best option is Doctrine preupdate event doc

提交回复
热议问题