在symfony中覆盖FormType

时间:2015-08-07 21:12:24

标签: symfony override

我有一个问题,如何在我的应用程序中覆盖symfony2中的FormType

我的班级是

class ContactType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('firstName', 'text', array('label' => 'mremi_contact.form.first_name'))
                ->add('lastName', 'text', array('label' => 'mremi_contact.form.last_name'))
                ->add('email', 'email', array('label' => 'mremi_contact.form.email'));

        if ($subjects = $this->subjectProvider->getSubjects()) {
            $builder
                    ->add('subject', 'choice', array(
                        'choices' => $subjects,
                        'label' => 'mremi_contact.form.subject',
            ));
        } else {
            $builder->add('subject', 'text', array('label' => 'mremi_contact.form.subject'));
        }

        $builder->add('message', 'textarea', array('label' => 'mremi_contact.form.message'));

        if ($this->captchaType) {
            $builder->add('captcha', $this->captchaType, array(
                'label' => 'mremi_contact.form.captcha',
                'mapped' => false,
            ));
        }

        $builder->add('save', 'submit', array('label' => 'mremi_contact.form_submit'));
    }

    public function getParent() {
        return 'mremi_contact';
    }

    public function getName() {
        return 'mremi_contact_contact_custom';
    }

}

我的服务是:mybundle \ ressources \ config \ services.yml

services:
    mremi_contact.custom_contact.form.type:
        class: Common\ContactBundle\Form\Type\ContactType
        tags:
            - { name: form.type, alias: mremi_contact_contact_custom }

我在我的app / config

中声明了它
# Mremi ContactBundle
mremi_contact:        
    form:
        type:              mremi_contact_contact_custom
        name:              contact_form
        validation_groups: [Default]
        subject_provider:  mremi_contact.subject_provider.noop
        captcha_type:      ewz_recaptcha

    email:
        mailer:            mremi_contact.mailer.twig_swift
        from:              []
        to:                
            - { address: thamer.nasri@gmail.com }
        template:          MremiContactBundle:Contact:email.txt.twig

错误是 无法加载类型" mremi_contact_contact_custom" 请帮我谢谢

0 个答案:

没有答案