title: How to filter entities in form selects based on ACLs
body: <p>Here is what I am trying to accomplish:</p>
  
  <p>I have a simple app that manages product and category entities. The CRUD for these is managed with SonataAdmin.</p>
  
  <p>My <code>Product</code> entity is associated with the <code>Category</code> entity (many-to-one association). What I want is that when Sonata's CRUD shows the form to create Products, in the category select, it lists only the categories on which the user has an <code>EDIT</code> Access Control Entry.</p>
  
  <p>Here is some code to illustrate this:</p>
  
  <p><code>Product</code> entity</p>
  
  <pre><code>&lt;?php
  
  namespace Acme\DemoBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Product
   *
   * @ORM\Table()
   * @ORM\Entity
   * @ORM\HasLifecycleCallbacks()
   */
  class Product
  {
  
      /**
       * @var integer id
       *
       * @ORM\Id
       * @ORM\Column(name="id", type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=255)
       */
      private $name;
  
      /**
       * @var float
       *
       * @ORM\Column(name="price", type="float")
       */
      private $price;
  
      /**
       * @var string
       *
       * @ORM\Column(name="description", type="text")
       */
      private $description;
  
      /**
       * @ORM\ManyToOne(targetEntity="Category", inversedBy="products")
       * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
       */
      protected $category;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /*Getters and setters
      ...
      */
  }
  </code></pre>
  
  <p><code>Category</code> entity</p>
  
  <pre><code>&lt;?php
  
  namespace Acme\DemoBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * Category
   *
   * @ORM\Table()
   * @ORM\Entity
   */
  class Category
  {
      /**
       * @var integer
       *
       * @ORM\Id
       * @ORM\Column(name="id", type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=255)
       */
      private $name;
  
      /**
       * @ORM\OneToMany(targetEntity="Product", mappedBy="category")
       */
      protected $products;
  
      public function __construct()
      {
          $this-&gt;products = new ArrayCollection();
      }
  
      /*Getters and setters
      ...
      */
  }
  </code></pre>
  
  <p>The <code>ProductAdmin</code> for Sonata CRUD</p>
  
  <pre><code>&lt;?php
  
  namespace Acme\DemoBundle\Admin;
  
  use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
  use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
  use Symfony\Component\Security\Acl\Permission\MaskBuilder;
  
  use Sonata\AdminBundle\Admin\Admin;
  use Sonata\AdminBundle\Datagrid\ListMapper;
  use Sonata\AdminBundle\Datagrid\DatagridMapper;
  use Sonata\AdminBundle\Form\FormMapper;
  
  class ProductAdmin extends Admin
  {
  
      // Fields to be shown on create/edit forms
      protected function configureFormFields(FormMapper $formMapper)
      {
          $formMapper
              -&gt;add('name', 'text', array('label' =&gt; 'Product name'))
  
              // HOWTO FILTER THESE ???
              -&gt;add('category', 'entity', array('class' =&gt; 'Acme\DemoBundle\Entity\Category'))
  
              -&gt;add('price')
              -&gt;add('description')
          ;
      }
  
      /* More here, but kept short for the example
      ...
      */
  
  }
  </code></pre>
  
  <p>What I'd like is a way to check for ACL in the <code>ProductAdmin::configureFormFields</code> whithin the call to <code>-&gt;add('category', 'entity', array('class' =&gt; 'Acme\DemoBundle\Entity\Category'))</code></p>
  
  <p>Any help much appreciated.
  FL.</p>