I am using SonataAdminBundle for the first time in my life, and I have some problems with it.
First I had a PageBundle which has a Page and Author object. Then I started using SonataAdminBundle and perfectly used sonata_type_model display Author in Page :
But then I discovered SonataUserBundle. I started using it, and when I finally started working, I thought it would be nice to use this User object rather than the Author object in the PageBundle. To make this possible, I used the technique described in the documentation on How to Define Relationships with Abstract Classes and Interfaces .
This worked, but not with the SonataAdminBundle. It seems that sonata_type_model does not work with ResolveTargetEntityListener , and I cannot make it work.
The corresponding Page object code in PageBundle:
namespace Wj\PageBundle\Entity; use Doctrine\ORM\Mapping as ORM; class Page { private $author; }
Wj\PageBundle\Model\AuthorInterface :
namespace Wj\PageBundle\Model; interface AuthorInterface { public function getId(); }
And the User object in the UserBundle:
namespace Wj\UserBundle\Entity; use Sonata\UserBundle\Entity\BaseUser; use Wj\PageBundle\Model\AuthorInterface; use Doctrine\ORM\Mapping as ORM; class User extends BaseUser implements AuthorInterface { protected $id; public function __toString() { return $this->getFirstName().' '.$this->getLastName(); } }
The configuration of FormMapper is the same as I posted above.
How to use the ResolveTargetEntityListener method in combination with SonataAdminBundle and its sonata_type_model ?
Wouter j
source share