mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Chill\MainBundle\Form;
|
|
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
use Chill\MainBundle\Form\UserPasswordType;
|
|
|
|
class UserType extends AbstractType
|
|
{
|
|
/**
|
|
* @param FormBuilderInterface $builder
|
|
* @param array $options
|
|
*/
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder
|
|
->add('username')
|
|
;
|
|
if ($options['is_creation']) {
|
|
$builder->add('plainPassword', new UserPasswordType(), array(
|
|
'mapped' => false
|
|
));
|
|
|
|
} else {
|
|
$builder->add($builder
|
|
->create('enabled', ChoiceType::class, array(
|
|
'choices' => array(
|
|
0 => 'Disabled, the user is not allowed to login',
|
|
1 => 'Enabled, the user is active'
|
|
),
|
|
'expanded' => false,
|
|
'multiple' => false
|
|
))
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param OptionsResolverInterface $resolver
|
|
*/
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults(array(
|
|
'data_class' => 'Chill\MainBundle\Entity\User'
|
|
));
|
|
|
|
$resolver
|
|
->setDefaults(array('is_creation' => false))
|
|
->addAllowedValues('is_creation', array(true, false))
|
|
;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getBlockPrefix()
|
|
{
|
|
return 'chill_mainbundle_user';
|
|
}
|
|
}
|