Persist and flush a given entity

@param $entity

@param string $entityManager
194847
public function persistAndFlush($entity, $persistAll = false, $entityManager = null)
    {
        $entityManager = $this->getEntityManager($entityManager);

        $entityManager->persist($entity);
        $entityManager->flush($persistAll ? null : $entity);
    }
1349436
public function saveEntity($entity)
    {
        if (!$this->entityManager->contains($entity)) {
            $this->entityManager->persist($entity);
        }

        $this->entityManager->flush();
        return true;
    }
1312742
protected function updateField(Entity $entity, $field) {
		if ($entity->dirty($field)) {
			return;
		}

		$entity->set($field, $this->getUserId());
	}
981066
final public function save(BaseEntityInterface $entity, $flush = false): self
    {
        $this->_em->persist($entity);

        if (true === $flush) {
            $this->_em->flush();
        }

        return $this;
    }
363168
public function moveAfter($entity)
    {
        if ($this->parent_id == $entity->parent_id) {
            $this->position = $entity->position + 1;
            $this->save();
        } else {
            $this->moveTo($entity->position + 1, $entity->parent_id);
        }
    }
1265030
public function injectEntityManager(EntityManagerInterface $entityManager, ClassMetadata $classMetadata) : void
    {
        if ($entityManager !== self::$entityManager) {
            throw new RuntimeException(
                'Trying to use PersistentObject with different EntityManager instances. ' .
                'Was PersistentObject::setEntityManager() called?'
            );
        }

        $this->cm = $classMetadata;
    }
532443
protected function update(Entity $entity) {
		$this->updateActiveRow($entity);
		$this->referencesUpdate($entity, $entity->getLoadedReferences());
	}
180774
public function initialize(Entity\Entity $entity)
    {
        $this->setupContenttype($entity);
        $this->setupContainer($entity);
    }
1305345
public function afterSave(Event $event, EntityInterface $entity): void
    {
        $action = $entity->isNew() ? ModelHistory::ACTION_CREATE : ModelHistory::ACTION_UPDATE;

        $dirtyFields = null;
        if ($action === ModelHistory::ACTION_UPDATE && isset($this->_dirtyFields[$entity->id])) {
            $dirtyFields = $this->_dirtyFields[$entity->id];
            unset($this->_dirtyFields[$entity->id]);
        }

        $this->ModelHistory->add($entity, $action, $this->_getUserId(), [
            'dirtyFields' => $dirtyFields
        ]);
    }
998653
private function getEntityOnFlush($entity, $flushEntity)
    {
        if (ClassUtils::getClass($entity) == ClassUtils::getClass($flushEntity) && $entity->getId() === $flushEntity->getId()) {
            return $flushEntity;
        } else {
            return $entity;
        }
    }
289344
public function save(Entity $entity) {
    $this->_em->persist($entity);
    $this->_em->flush();
    return $this;
  }
1336909
protected function crudManage($entity, $action)
    {
        // Before, send preAction
        $event = $this->dispatchPreActionCrudEvent($entity, $action);
        $em = $this->getDoctrine()->getManager();

        // Update entity according to action (can be changed in event)
        switch ($event->getAction()) {
            case AdminCrudEvent::CREATE;
                $em->persist($entity);
                break;
            case AdminCrudEvent::DELETE;
                $em->remove($entity);
                break;
        }
        if ($action > AdminCrudEvent::DONT_TOUCH) {
            $em->flush();
        }

        // Send postAction Event
        $event = $this->dispatchPostActionCrudEvent($entity, $action);

        switch ($event->getAction()) {
            case AdminCrudEvent::CREATE;
                $this->addFlashMessage('success', $this->getFlashCreatedMessage());
                break;
            case AdminCrudEvent::DELETE;
                $this->addFlashMessage('success', $this->getFlashDeletedMessage());

                return $this->redirect($this->getListUrl());
                break;
            case AdminCrudEvent::UPDATE;
                $this->addFlashMessage('success', $this->getFlashSavedMessage());
                break;

        }

        return $this->redirect($this->getShowUrl($entity));
    }
590379
public function afterSave(Event $event, EntityInterface $entity)
    {
        $property = $this->versionAssociation()->getProperty();
        $entity->unsetProperty($property);
    }
611796
public function save(AbstractEntity $entity)
    {
        if (empty($entity->getId())) {
            $this->getEntityManager()->persist($entity);
        }
        $this->getEntityManager()->flush($entity);
    }
599094
public function insert($entity)
    {
        $persistor = new CsvPersistor(
            $this->gateway,
            $this->table,
            $this->entityRegistry->getEntityBuilder(),
            $this->entityRegistry
        );
        $persistor->insert($entity);
    }
658482
protected function saveEntity($entity)
    {
        try {
            $this->entityManager->persist($entity);
            $this->entityManager->flush($entity);
            return $entity;
        } catch (OptimisticLockException $e) {
            throw new DatabaseException($e->getMessage());
        }
    }
1277001
protected function _save(EntityInterface $entity)
    {
        $entity = $this->_table()->patchEntity(
            $entity,
            ['verified' => true],
            $this->saveOptions()
        );
        $subject = $this->_subject(['entity' => $entity]);

        $this->_trigger('beforeSave', $subject);

        $success = call_user_func(
            [$this->_table(), $this->saveMethod()],
            $entity,
            $this->saveOptions()
        );

        $this->_trigger('afterSave', $subject);

        return $success;
    }