tmschneider
tmschneider

Reputation: 7

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.

Upvotes: 0

Views: 181

Answers (1)

Mitchel
Mitchel

Reputation: 51

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;
}

Upvotes: 1

Related Questions