I'm starting with EasyAdmin v3. I want to set a default value in easyAdmin. In php/symfony i would provide:
$article = new Article::class;
$article->setAuthor($user)
Before creating the form to set the currentUser in my entity but with EA3 i don't know how to manage this.
Thanks
You can override methods like createEntity()
:
class ArticleCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Article::class;
}
public function createEntity(string $entityFqcn)
{
$article = new Article();
$article->setAuthor($this->getUser())
return $article;
}
// ...
}
See this part of the documentation for more information.