Я пытаюсь удалить поле имени пользователя из регистрационной формы FOSUserBundle, как описано в шаге 2 в этом ответе.
Это класс FormType, который я создал, чтобы переопределить значение по умолчанию:
<?php
// src/UserBundle/Form/Type/RegistrationFormType.php
namespace UserBundle\Form\Type;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseFormType;
class RegistrationFormType extends BaseFormType
{
public function buildForm(FormBuilder $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->remove('username');
}
}
Однако поля пользователя по-прежнему отображаются в форме. Что мне не хватает?
Вы не переопределяете форму-сервис в конфигурации пакета.
Поэтому FOSUserBundle не использует ваш тип формы.
# register your form-type as a service ...
services:
my_custom_user_registration_form:
class: "UserBundle\Form\Type\RegistrationFormType"
# ... then tell FOSUserBundle to use this form-type service instead of the default
fos_user:
...
registration:
form:
type: my_custom_user_registration_form
imports
вapp/config/config.yml
:- { resource: "@UserBundle/Resources/config/services.yml" }
Кроме того, мне нужно было добавитьuse Symfony\Component\Form\FormBuilderInterface;
toRegistrationFormType.php
.