Created
December 21, 2015 17:20
-
-
Save Raistlfiren/6de6a7a4bedd2027a25c to your computer and use it in GitHub Desktop.
Password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//UserAdmin Form | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle')) | |
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle')) | |
->add('firstName', null, array('label' => 'form.firstname')) | |
->add('lastName', null, array('label' => 'form.lastname')) | |
->add('address1', null, array('label' => 'form.fax')) | |
->add('city', null, array('label' => 'form.city')) | |
->add('state', null, array('label' => 'form.state')) | |
->add('zipcode', null, array('label' => 'form.zipcode')) | |
->add('primaryPhone', null, array('label' => 'form.primaryPhone')) | |
->add('altPhone', null, array('label' => 'form.altPhone')) | |
; | |
$builder->addEventSubscriber(new PasswordFieldSubscriber()); | |
} | |
//Subscriber | |
namespace FA\BackEnd\UserAdminBundle\Form\EventListener; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Symfony\Component\Form\FormEvent; | |
use Symfony\Component\Form\FormEvents; | |
class PasswordFieldSubscriber implements EventSubscriberInterface | |
{ | |
public static function getSubscribedEvents() | |
{ | |
return array(FormEvents::PRE_SET_DATA => 'preSetPassword'); | |
} | |
public function preSetPassword(FormEvent $event) | |
{ | |
$user = $event->getData(); | |
$form = $event->getForm(); | |
$required = true; | |
if ($user->getId()) { | |
$required = false; | |
} | |
$form->add('plainPassword', 'repeated', array( | |
'type' => 'password', | |
'options' => array('translation_domain' => 'FOSUserBundle'), | |
'required' => $required, | |
'first_options' => array('label' => 'form.password'), | |
'second_options' => array('label' => 'form.password_confirmation'), | |
'invalid_message' => 'fos_user.password.mismatch', | |
)); | |
return $required; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment