EasyAdminBundle
EasyAdminBundle copied to clipboard
Pass AdminContext to createEntity
Short description of what this feature will allow to do: By overriding createEntity method, you can set default values for the form. However, I'd like to set the default value depending on a url parameter like this:
For example, if you have:
https://some_website.com/some_entity/edit?some_value=something
Then depending on that some_value, I would like to set the default value for some field.
For that I need AdminContext, so it would be good to have AdminContext as argument of createEntity() method.
Example of how to use this feature
public function createEntity(string $entityFqcn, AdminContext $context)
{
// create the entity with values depending on $context
}
Answering to myself:
I think it can be done like this:
$request = $this->getContext()->getRequest();
$some_value = $request->query->get('some_value');
I haven't tested that yet though.
In other words, the feature is not needed because you can retrieve the context with $this->getContext().