em->getRepository($this->entity['class'])->findOneBy([]); if (!$entity) { $entity = new $this->entity['class'](); try { $this->em->persist($entity); $this->em->flush(); } catch (OptimisticLockException | ORMException $exception) { // redirect to admin's default entity when section creation failed return $this->redirectToRoute('admin'); } } $this->request->query->set('id', $entity->getId()); $this->request->attributes->set( 'easyadmin', array_merge($this->request->attributes->get('easyadmin'), ['item' => $entity]) ); return parent::editAction(); } }