升级到 Symfony 3 后,自定义 FormType 出现问题

After upgrading to Symfony 3 a custom FormType gives problems

我一直在 Symfony 2.8 上使用 OhGoogleMapFormTypeBundle 的稍微改编版本作为 LocationType/MapType 到我自己的包中。升级到 Symfony 3.2 后,在尝试保存为位置填写的数据时出现错误

Neither the property "lat" nor one of the methods "getLat()", "lat()", "isLat()", "hasLat()", "__get()" exist and have public access in class "LocationBundle\Form\LocationType".

自定义 FormType 通过 LocationType::class 包含在另一个 FormType (NodeType) 中。

我一直在查看 Symfony 中的变化,特别是 Form 组件,以查看是否有什么影响数据 read/written 进入实体的方式,但找不到任何东西。

LocationType 中包含 MapType 的代码是

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('LatLng', MapType::class, array(
            'default_lat' => '37.06394430056685',
            'default_lng' => '-3.09814453125',
            'map_width' => 600,
            'type' => HiddenType::class
        ))
        ;
}

在最终视图(浏览器)中,字段是用

收集的
<input id="node_Location_LatLng_lat" name="node[Location][LatLng][lat]" value="36.945971" type="hidden"><input id="node_Location_LatLng_lng" name="node[Location][LatLng][lng]" value="-3.1785935000000336" type="hidden">

我的实体不应该接收 Array LatLng 而不是其组件吗?这就是它在更新到 Symfony 3 之前的工作方式。

我是不是做错了什么?我需要定义缺少的方法吗?我是否必须实施 ValueTransformer.. 但是,为什么以前没有必要?

我发现了问题。在 MapType::configureOptions() 中,我定义了 'data_class' => LocationType::class,而它应该是 'data_class' => 'LocationBundle\Entity\Location'

这一定是在将代码转换为 Symfony3 规则时发生的。我把问题留给其他人...甚至我自己。