111 lines
2.6 KiB
PHP
111 lines
2.6 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace Trinity\Bundle\UserBundle\Form\Type;
|
|||
|
|
|||
|
use Propel\PropelBundle\Form\BaseAbstractType;
|
|||
|
use Symfony\Component\Form\FormBuilderInterface;
|
|||
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
|||
|
|
|||
|
class UserType extends BaseAbstractType
|
|||
|
{
|
|||
|
/**
|
|||
|
* {@inheritdoc}
|
|||
|
*/
|
|||
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|||
|
{
|
|||
|
$builder->add(
|
|||
|
'username',
|
|||
|
null,
|
|||
|
array(
|
|||
|
'label' => 'Username'
|
|||
|
)
|
|||
|
);
|
|||
|
|
|||
|
$builder->add(
|
|||
|
'email',
|
|||
|
'email',
|
|||
|
array(
|
|||
|
'label' => 'Email'
|
|||
|
)
|
|||
|
);
|
|||
|
|
|||
|
$builder->add(
|
|||
|
'plainPassword',
|
|||
|
'repeated',
|
|||
|
array(
|
|||
|
'type' => 'password',
|
|||
|
'attr' => array(
|
|||
|
'class' => 'embeded-form',
|
|||
|
)
|
|||
|
)
|
|||
|
);
|
|||
|
|
|||
|
$builder->add(
|
|||
|
'groups',
|
|||
|
'model',
|
|||
|
array(
|
|||
|
'class' => 'FOS\UserBundle\Propel\Group',
|
|||
|
'multiple' => true,
|
|||
|
'expanded' => false,
|
|||
|
'attr' => array(
|
|||
|
'class' => 'chosen-select',
|
|||
|
'data-placeholder' => 'Sélectionnez un groupe'
|
|||
|
),
|
|||
|
)
|
|||
|
);
|
|||
|
|
|||
|
$builder->add('enabled');
|
|||
|
|
|||
|
$builder->add(
|
|||
|
'profile',
|
|||
|
new ProfileType(),
|
|||
|
array(
|
|||
|
'attr' => array(
|
|||
|
'class' => 'embeded-form',
|
|||
|
)
|
|||
|
)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* {@inheritdoc}
|
|||
|
*/
|
|||
|
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
|||
|
{
|
|||
|
$resolver->setDefaults(
|
|||
|
array(
|
|||
|
'validation_groups' => 'Profile',
|
|||
|
'data_class' => 'FOS\UserBundle\Propel\User',
|
|||
|
'cascade_validation' => true,
|
|||
|
'roles' => array()
|
|||
|
)
|
|||
|
);
|
|||
|
|
|||
|
parent::setDefaultOptions($resolver);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* {@inheritdoc}
|
|||
|
* Name must be the same as the service alias for tag form
|
|||
|
*/
|
|||
|
public function getName()
|
|||
|
{
|
|||
|
return 'trinity_user_admin_form';
|
|||
|
}
|
|||
|
|
|||
|
public static function getRoles()
|
|||
|
{
|
|||
|
return array(
|
|||
|
'ROLE_USER' => 'User',
|
|||
|
'ROLE_WEBMASTER' => 'Webmaster',
|
|||
|
'ROLE_ADMIN' => 'Administrator',
|
|||
|
'ROLE_SUPER_ADMIN' => 'Super administrator'
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
public static function validatorRoles()
|
|||
|
{
|
|||
|
return array_keys(self::getRoles());
|
|||
|
}
|
|||
|
}
|