title: How to get underlying object in Sonata's Admin class when called by sonata_type_admin?
body: <p>So, in edit action of Sonata Admin I'm trying to display different form fields depending on <em>create</em> or <em>edit</em> context.</p>
  
  <p>Maybe some background first..</p>
  
  <p>I have a Gallery entity and a CoverPhoto entity bound with OneToOne.</p>
  
  <p><strong>Gallery:</strong></p>
  
  <pre><code>/**
   * @ORM\OneToOne(targetEntity="CoverImage", mappedBy="gallery", cascade={"all"}, orphanRemoval=true)
   **/
  private $cover;
  </code></pre>
  
  <p><strong>CoverImage:</strong></p>
  
  <pre><code>/**
   * @ORM\OneToOne(targetEntity="Gallery", inversedBy="cover")
   **/
  private $gallery; 
  </code></pre>
  
  <p>Here's coresponding <strong>GalleryAdmin</strong> class:</p>
  
  <pre><code>class GalleriesAdmin extends Admin
  {
      protected function configureFormFields(FormMapper $formMapper)
      {
          $formMapper
                  -&gt; add('name', null, array('label' =&gt; 'Nazwa'))
                  -&gt; add('category', 'sonata_type_model', array('label' =&gt; 'Kategoria'), array('subject' =&gt; $this -&gt; getSubject()))
                  -&gt; add('cover', 'sonata_type_admin', array('label' =&gt; 'Okładka'))
                  -&gt; add('images', 'sonata_type_collection', array('by_reference' =&gt; false, 'label' =&gt; 'Powiązane zdjęcia'), array(
                      'edit' =&gt; 'inline',
                      'sortable' =&gt; false,
                      'inline' =&gt; 'table',
                  ))
              ;
      }
  
      //other stuff 
  }
  </code></pre>
  
  <p>And here we go with <strong>CoverImageAdmin</strong>:</p>
  
  <pre><code>class CoverImagesAdmin extends Admin
  {
      protected function configureFormFields(FormMapper $formMapper)
      {
          $formMapper
                  -&gt; add('path', 'thumbnail', array('label' =&gt; 'Miniatura'))
                  -&gt; add('file', 'file', array('required' =&gt; false, 'label' =&gt; 'Plik'))
          ;
      }
  }
  </code></pre>
  
  <p>"Thumbnail" is my custom form field which displays thumbnail (shocker). But now i want this field only appear in "edit" context. </p>
  
  <p>This should be piece of cake with </p>
  
  <pre><code>$this -&gt; getSubject()
  </code></pre>
  
  <p>method of Admin class and condition. Unfortunately when I call getSubject() in CoverImagesAdmin class which is used to render nested form it always returns <em>null</em>. The same with getParent();</p>
  
  <p>Calling getForm() results in </p>
  
  <blockquote>
    <p>Fatal error: Maximum function nesting level of '500' reached, aborting! in 
    /home/flameheart/Projects/KolberPhotography/vendor/symfony/symfony/src/Symfony/Component
    /OptionsResolver/Options.php on line 350</p>
  </blockquote>
  
  <p>I've tried to call about every method of Admin and FormMapper just to determine form's context but ended up with nothing.</p>
  
  <p>Do you guys have any idea how to solve this in a clean way ?</p>