Using this Link
Remove / Replace the username field with email using FOSUserBundle in Symfony2 / Symfony3
I tried to remove the Username from the registration form by Overriding the FOS User Bundle.
Form Type class is working fine.
But while rendering, it throws
Method "username" for object "Symfony\Component\Form\FormView" does not exist in FOSUserBundle:Registration:register_content.html.twig at line 3
I tried with this link to avoid this
I couldn't. Need expert assistance regarding this.
Update 1:
I also tried this link
http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html
Form Type class:
/* * Overridden FOSUserBundle RegistrationFormType. */
namespace Test\RegistrationBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->remove('username',array("mapped"=>false));
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'app_user_registration';
}
}
Twig File:
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</div>