public function createResource(EntityInterface $entity, bool $flush = true) { $this->dispatchEvent(self::PRE_ENTITY_CREATE_EVENT, $entity); $this->getEntityManager()->persist($entity); $this->dispatchEvent(self::POST_ENTITY_CREATE_EVENT, $entity); if ($flush) { $this->getEntityManager()->flush(); } }