2
votes

I am working on a Symfony 2,8 project with Sonata. I found that the users are managed with FOS :

namespace Voyage\AdminBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;

class UserCoreAdmin extends Admin {

    /**
     * {@inheritdoc}
     */
    public function getFormBuilder() {
        //...
    }

    /**
     * {@inheritdoc}
     */
    public function getExportFields() {
        // avoid security field to be exported
    }

    /**
     * {@inheritdoc}
     */
    protected function configureListFields(ListMapper $listMapper) {
        //...
    }

    /**
     * {@inheritdoc}
     */
    protected function configureDatagridFilters(DatagridMapper $filterMapper) {
       //...
    }

    /**
     * {@inheritdoc}
     */
    protected function configureShowFields(ShowMapper $showMapper) {
    //...
    }

    /**
     * {@inheritdoc}
     */
    protected function configureFormFields(FormMapper $formMapper) {
        //...
    }
    /**
     * {@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;
    }
}

And i get this error while doing a user update :

Notice: Undefined property: Voyage\AdminBundle\Admin\UserCoreAdmin::$userManager

500 Internal Server Error - ContextErrorException

2

2 Answers

0
votes

You should extend Sonata\UserBundle\Admin\Entity\UserAdmin, it should have this property, as opposed to Sonata\AdminBundle\Admin\Admin.

0
votes

It was a missing config in the services.yml, a call to SetUserManager was missing.

- [ setUserManager, [ @fos_user.user_manager]]