chill-bundles/Form/UserType.php

66 lines
1.8 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', UserPasswordType::class, array(
'mapped' => false
));
} else {
$builder->add($builder
->create('enabled', ChoiceType::class, array(
'choices' => array(
'Disabled, the user is not allowed to login' => 0,
'Enabled, the user is active' => 1
),
'expanded' => false,
'multiple' => false,
'choices_as_values' => true // Can be removed when upgraded to Sf3.
))
);
}
}
/**
* @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';
}
}