类没有实现“Symfony\Component\Form\FormTypeInterface";在西里乌斯 [英] Class does not implement "Symfony\Component\Form\FormTypeInterface" in Sylius

查看:31
本文介绍了类没有实现“Symfony\Component\Form\FormTypeInterface";在西里乌斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试从 CustomerProfileType 扩展,但我们收到如下错误:

We are trying to extend from CustomerProfileType and we are getting error like:

 {
"code": 500,
"message": "Could not load type "abc\Form\Extension\AdminApi\CustomerProfileTypeExtension": class does not implement "Symfony\Component\Form\FormTypeInterface"."
}

Customer.yml:

Customer.yml:

sylius_admin_api_customer_create:
    path: /
    methods: [POST]
    defaults:
        _controller: sylius.controller.customer:createAction
        _sylius:
            serialization_version: $version
            serialization_groups: [Detailed]
            form:
                type: abc\Form\Extension\AdminApi\CustomerProfileTypeExtension

CustomerProfileTypeExtension.php

CustomerProfileTypeExtension.php

final class CustomerProfileTypeExtension extends AbstractTypeExtension
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        // Adding new fields works just like in the parent form type.
        $builder->add('contactHours', TextType::class, [
            'required' => false,
            'label' => 'app.form.customer.contact_hours',
        ]);

        // To remove a field from a form simply call ->remove(`fieldName`).
        $builder->remove('gender');

        // You can change the label by adding again the same field with a changed `label` parameter.
        $builder->add('lastName', TextType::class, [
            'label' => 'app.form.customer.surname',
        ]);
    }


    /**
     * {@inheritdoc}
     */
    public function getExtendedType(): string
    {
        return CustomerProfileType::class;
    }


}

推荐答案

您是否通过传递实体来调用 createForm 方法?

Are you calling createForm method by passing your entity ?

如果是这样,那么您可能忘记插入为实体创建的 formType 类.这是我做错的地方.

If so then you might forget to insert the formType class you created for the entity. This is where i was doing mistake.

就我而言,我写了 $form = $this->createForm(Article::class);

但是代码应该是 $form = $this->createForm(ArticleFormType::class);

这篇关于类没有实现“Symfony\Component\Form\FormTypeInterface";在西里乌斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆