UserAdmin.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\UserBundle\Admin\Entity;
  11. use Sonata\AdminBundle\Admin\Admin;
  12. use Sonata\AdminBundle\Form\FormMapper;
  13. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  14. use Sonata\AdminBundle\Datagrid\ListMapper;
  15. use Sonata\AdminBundle\Route\RouteCollection;
  16. class UserAdmin extends Admin
  17. {
  18. protected $list = array(
  19. 'username' => array('identifier' => true),
  20. 'email',
  21. 'enabled',
  22. 'locked',
  23. 'createdAt',
  24. );
  25. protected $formGroups = array(
  26. 'General' => array(
  27. 'fields' => array('username', 'email', 'plainPassword')
  28. ),
  29. 'Groups' => array(
  30. 'fields' => array('groups')
  31. ),
  32. 'Management' => array(
  33. 'fields' => array('roles', 'locked', 'expired', 'enabled', 'credentialsExpired', 'credentialsExpireAt')
  34. )
  35. );
  36. protected $formOptions = array(
  37. 'validation_groups' => 'admin'
  38. );
  39. protected $filter = array(
  40. 'username',
  41. 'locked',
  42. 'email',
  43. 'id',
  44. );
  45. public function configureFormFields(FormMapper $formMapper)
  46. {
  47. $formMapper
  48. ->add('username')
  49. ->add('email')
  50. ->add('groups', array('required' => false))
  51. ->add('locked', array('required' => false))
  52. ->add('expired', array('required' => false))
  53. ->add('enabled', array('required' => false))
  54. ->add('credentialsExpired', array('required' => false))
  55. ;
  56. $formMapper->addType('roles', 'sonata_security_roles', array(
  57. 'multiple' => true,
  58. // 'expanded' => true,
  59. ), array(
  60. 'type' => 'choice'
  61. ));
  62. }
  63. }