无法覆盖 Sonata User Bundle 注册表格

Unable to override Sonata User Bundle registration form

我在尝试覆盖奏鸣曲注册模板时不断收到错误消息。

我用 EasyExtendsBundle 扩展了 Sonata User Bundle,所以我现在有 src/Application/Sonata/UserBundle。

编辑: Symfony 2.7,Sonata Admin 2.3,Sonata User dev-master

我在我的用户实体中添加了一个字段 UserEntity.php

<?php

/**
 * This file is part of the <name> project.
 *
 * (c) <yourname> <youremail>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Application\Sonata\UserBundle\Entity;

use Sonata\UserBundle\Entity\BaseUser as BaseUser;

/**
 * This file has been generated by the Sonata EasyExtends bundle ( http://sonata-project.org/bundles/easy-extends )
 *
 * References :
 *   working with object : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
 *
 * @author <yourname> <youremail>
 */
class User extends BaseUser
{
    /**
     * @var integer $id
     */
    protected $id;

   /*
     * @ORM\Column(type="string", length=255)
     *
     * @Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"})
     */
     protected $age;

    /**
     * Get id
     *
     * @return integer $id
     */
    public function getId()
    {
        return $this->id;
    }

     public function getAge()
    {
        return $this->age;
    }

        public function setAge($age)
    {
         $this->age = $age;
    }
}

然后我创建了一个新的 RegisterForm Application/Sonata/UserBundle/Form/Type/RegisterType.php

<?php

namespace Application\Sonata\UserBundle\Form\Type;

use FOS\UserBundle\Form\Type\RegistrationFormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class RegisterType extends RegistrationFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {

        parent::buildForm($builder, $options);

        $builder
            ->add('age');
    }

    public function setDefaultOption(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'validation_groups' => array('Default', 'Register')
        ));
    }

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

我告诉 sonata_user 使用我的表格 config.yml

sonata_user:
    profile:
        register:
            form:
                type:               front_user_registration
                handler:            sonata.user.profile.form.handler.default
                name:               front_user_registration_form

fos_user:
    db_driver:      orm # can be orm or odm
    firewall_name:  main

    # if you change the class configuration, please also alter the sonata_user.yml file
    user_class:     Application\Sonata\UserBundle\Entity\User

    group:
        group_class:   Application\Sonata\UserBundle\Entity\Group
        group_manager: sonata.user.orm.group_manager

    service:
        user_manager: sonata.user.orm.user_manager
    registration:
        form:
            type: front_user_registration
    profile:
        form:
            type:               fos_user_profile
            handler:            fos_user.profile.form.handler.default
            name:               fos_user_profile_form
            validation_groups:  [Authentication]

我声明为服务 services.yml

user.form.register.type:
        class: Application\Sonata\UserBundle\Form\Type\RegisterType
        parent: fos_user.registration.form.type
        tags:
            - { name: form.type, alias: front_user_registration }

当我尝试显示表单时,出现以下错误:

Catchable Fatal Error: Argument 1 passed to Sonata\UserBundle\Form\Handler\ProfileFormHandler::process() must implement interface FOS\UserBundle\Model\UserInterface, boolean given, called in /Users/sylv/Sites/generajobs/vendor/sonata-project/user-bundle/Controller/RegistrationFOSUser1Controller.php on line 49 and defined

如果我添加也一样

arguments: [%fos_user.model.user.class%]

进入我的 services.yml 配置。

我是不是遗漏了什么?

这是一个非常愚蠢的错误,我不得不将 config.yml 中的 "handler" 行更改为

handler:            sonata.user.registration.form.handler.default

而不是 sonata.user.profile.form.handler.default,正如我在 S.O 上的几个示例中看到的那样。

两个handlers process()函数除了参数相同外