How to properly call entity form? I have created a wrapper in form of a "page" controller for my entity's form because I needed to do some tasks before it was rendered.

I ended up with this:

&lt;?php
  class MyEntityController extends ControllerBase {
    public function mymethod(AnotherEntity $anotherEntity) {
      $myentity = $this-&gt;entityManager()-&gt;getStorageController('myentity')-&gt;create(array());
      $form = $this-&gt;entityManager()-&gt;getFormController('myentity', 'default');
      $form-&gt;setEntity($myentity);
      $form-&gt;setParentEntity($anotherEntity);
      $form-&gt;setRedirectRoute(array(
        'route_name' =&gt; 'some.route',
        'route_parameters' =&gt; array('somearugment' =&gt; $anotherEntity-&gt;id()
      ));
      return $this-&gt;formBuilder()-&gt;getForm($form);
    }
  }
?&gt;


Is this the recommended way in regard of the entity form itself(ie. manually setting the form's entity object)?
&lt;?php
class MyEntityController extends ControllerBase {
  public function mymethod(AnotherEntity $anotherEntity) {
    // @todo The methods don't exist in core, so it's not clear what object they
    //   should be called on.
    //$form-&gt;setParentEntity($anotherEntity);
    //$form-&gt;setRedirectRoute(array(
    //  'route_name' =&gt; 'some.route',
    //  'route_parameters' =&gt; array('somearugment' =&gt; $anotherEntity-&gt;id()
    //));

    $myentity = $this-&gt;entityManager()-&gt;getStorageController('myentity')-&gt;create(array());
    return $this-&gt;entityFormBuilder()-&gt;getForm($myentity, 'default');
  }
}
?&gt;