123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /*
- * This file is part of the Sonata package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\UserBundle\Admin\Model;
- use Sonata\AdminBundle\Admin\Admin;
- use Sonata\AdminBundle\Form\FormMapper;
- use Sonata\AdminBundle\Datagrid\DatagridMapper;
- use Sonata\AdminBundle\Datagrid\ListMapper;
- use FOS\UserBundle\Model\UserManagerInterface;
- class UserAdmin extends Admin
- {
- protected $formOptions = array(
- 'validation_groups' => 'Profile'
- );
- /**
- * {@inheritdoc}
- */
- protected function configureListFields(ListMapper $listMapper)
- {
- $listMapper
- ->addIdentifier('username')
- ->add('email')
- ->add('groups')
- ->add('enabled')
- ->add('locked')
- ->add('createdAt')
- ;
- if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
- $listMapper
- ->add('impersonating', 'string', array('template' => 'SonataUserBundle:Admin:Field/impersonating.html.twig'))
- ;
- }
- }
- /**
- * {@inheritdoc}
- */
- protected function configureDatagridFilters(DatagridMapper $filterMapper)
- {
- $filterMapper
- ->add('id')
- ->add('username')
- ->add('locked')
- ->add('email')
- ->add('groups')
- ;
- }
- /**
- * {@inheritdoc}
- */
- protected function configureFormFields(FormMapper $formMapper)
- {
- $formMapper
- ->with('General')
- ->add('username')
- ->add('email')
- ->add('plainPassword', 'text', array('required' => false))
- ->end()
- ->with('Groups')
- ->add('groups', 'sonata_type_model', array('required' => false))
- ->end()
- ->with('Management')
- ->add('roles', 'sonata_security_roles', array(
- 'expanded' => true,
- 'multiple' => true,
- 'required' => false
- ))
- ->add('locked', null, array('required' => false))
- ->add('expired', null, array('required' => false))
- ->add('enabled', null, array('required' => false))
- ->end()
- ;
- }
- /**
- * {@inheritdoc}
- */
- public function preUpdate($user)
- {
- $this->getUserManager()->updateCanonicalFields($user);
- $this->getUserManager()->updatePassword($user);
- }
- /**
- * @param UserManagerInterface $userManager
- */
- public function setUserManager(UserManagerInterface $userManager)
- {
- $this->userManager = $userManager;
- }
- /**
- * @return UserManagerInterface
- */
- public function getUserManager()
- {
- return $this->userManager;
- }
- }
|