Populate resp. set default values on form resp. object or instance in SonataAdminBundle

0 Flares Twitter 0 Facebook 0 LinkedIn 0 0 Flares ×

To set default values on a new instance you can override the getNewInstance() method in your Admin class:

This is a pretty basic example for setting columns that expect a string, bool etc.

If you need to set an related Object you can not simply pass an identifier (e.g. company_id). You will have to fetch the instance:

Fetching a complete Object actually causes some overhead. Instead it is recommended to only fetch the reference:

 See Doctrine documentation for details.

If you need to get the identifier from the Request you can use the getRequest() method:

 

The featured parts of the User Entity:

 

Backlinks:

Web Deviloper