2

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

loosemade
  • 45
  • 1
  • 9

1 Answers1

7

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.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97