简体   繁体   中英

Symfony 3 and Sonata Admin

I wish to know simply if it is possible to preload the create entity form with given values.

My application has a Daily Schedule view with 30 minute intervals. I want the user to be able to click on a time (eg:12:30) on the Daily Schedule and have it preload a Booking entity form along with the current date.

I have searched to no avail a solution, I would have thought this would be a common action.

I figure I need to access the instantiated object (the Booking) prior to it binding to the request however this is all handled by Sonata Admin. Is it possible to simply override the Create action to preload the form?

Thank you in advance.

Yes, it is. You could set defaults on your Booking entity or overwrite getNewInstance() in your Admin class, like so:

public function getNewInstance()
{
    $object = parent::getNewInstance();

    $object->setDefaults();

    return $object;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM