EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Pass AdminContext to createEntity

Open damc opened this issue 1 year ago • 1 comments

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
}

damc avatar Oct 16 '23 17:10 damc

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().

damc avatar Oct 16 '23 18:10 damc