As I was studying the default Form Builder of FosUserBundle for Editing a User Profile (FOS\UserBundle\Form\Type\ProfileFormType
) I noticed the following line of code:
$builder->add('current_password', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'), array(
'label' => 'form.current_password',
'translation_domain' => 'FOSUserBundle',
'mapped' => false,
'constraints' => new UserPassword($constraintsOptions),
));
And that render the filed "current password" But I want to edit a profile without needing to put the user password all over the time. Is there a way to do that?
Actually I tried to extend the form of FosUserBundle and I sucessfylly managed to add some new fields:
namespace AppUserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class UserProfileFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
//$builder->addViewTransformer($this->purifierTransformer);
$builder->add('name',TextType::class,array('label'=>'profile.first_name','required' => false));
$builder->add('surname',TextType::class,array('label'=>'profile.surnname','required' => false));
$builder->add('email',TextType::class,['required' => false]);
$builder->add('description',TextareaType::class,['required' => false]);
}
public function getParent()
{
return 'FOS\UserBundle\Form\Type\ProfileFormType';
}
public function getBlockPrefix()
{
return 'app_user_registration';
}
// For Symfony 2.x
public function getName()
{
return $this->getBlockPrefix();
}
}
But I cannot find a way to get rid the password validation and the field when I need to update the user profile of the currently logged in user WITHOUT the need for the user to type all over the time the password.
Edit 1
I tried
$builder->remove('current_password');
I got the following error:
Neither the property "current_password" nor one of the methods "current_password()", "getcurrent_password()"/"iscurrent_password()"/"hascurrent_password()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".