GroupAdmin.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project 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\Model;
  11. use Sonata\AdminBundle\Admin\AbstractAdmin;
  12. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  13. use Sonata\AdminBundle\Datagrid\ListMapper;
  14. use Sonata\AdminBundle\Form\FormMapper;
  15. class GroupAdmin extends AbstractAdmin
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected $formOptions = array(
  21. 'validation_groups' => 'Registration',
  22. );
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function getNewInstance()
  27. {
  28. $class = $this->getClass();
  29. return new $class('', array());
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function configureListFields(ListMapper $listMapper)
  35. {
  36. $listMapper
  37. ->addIdentifier('name')
  38. ->add('roles')
  39. ;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. protected function configureDatagridFilters(DatagridMapper $datagridMapper)
  45. {
  46. $datagridMapper
  47. ->add('name')
  48. ;
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. protected function configureFormFields(FormMapper $formMapper)
  54. {
  55. // NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
  56. $securityRolesType = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
  57. ? 'Sonata\UserBundle\Form\Type\SecurityRolesType'
  58. : 'sonata_security_roles';
  59. $formMapper
  60. ->tab('Group')
  61. ->with('General', array('class' => 'col-md-6'))
  62. ->add('name')
  63. ->end()
  64. ->end()
  65. ->tab('Security')
  66. ->with('Roles', array('class' => 'col-md-12'))
  67. ->add('roles', $securityRolesType, array(
  68. 'expanded' => true,
  69. 'multiple' => true,
  70. 'required' => false,
  71. ))
  72. ->end()
  73. ->end()
  74. ;
  75. }
  76. }