This event handler will update, insert or remove translation entities if
main object's translatable properties change.

@param PreFlushEventArgs $eventArgs
436785
public function preFlush(PreFlushEventArgs $eventArgs)
    {
        $entityManager = $eventArgs->getEntityManager();
        $unitOfWork = $entityManager->getUnitOfWork();

        foreach ($unitOfWork->getScheduledEntityInsertions() as $object) {
            $this->updateObjectTranslations($entityManager, $object);
        }

        foreach ($unitOfWork->getIdentityMap() as $entities) {
            foreach ($entities as $object) {
                $this->updateObjectTranslations($entityManager, $object);
            }
        }
    }
1120054
public function postLoad(EventArgs $eventArgs)
    {
        if (method_exists($eventArgs, 'getEntity')) {
            $this->_triggerEvent(Events::postLoad, $eventArgs->getEntity(), $eventArgs);
        }
    }
323808
public function prePersist($eventArgs)
    {
        $entity = $eventArgs->getEntity();

        foreach ($this->metadata->getManagedFields($entity) as $field) {
            $value = PropertyHelper::getValue($entity, $field);
            if (null !== $value) {
                $this->scheduleForUpload($value, $entity, $field);
            }
        }
    }
179620
public function postLoad(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if (!$entity instanceof TranslatableInterface) {
            return;
        }

        $entity->initializeTranslations();
        $entity->setCurrentLocale($this->localeProvider->getCurrentLocale());
        $entity->setFallbackLocale($this->localeProvider->getFallbackLocale());
    }
1188834
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $this->pages = new ArrayCollection();

        $this->manager = $eventArgs->getEntityManager();
        $uow = $this->manager->getUnitOfWork();

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            $this->handleEntity($entity);
        }
        /** @var \Doctrine\Common\Collections\ArrayCollection $col */
        foreach ($uow->getScheduledCollectionUpdates() as $col) {
            foreach ($col as $entity) {
                $this->handleEntity($entity);
            }
        }

        if (0 < $this->pages->count()) {
            $this->persister->replaceMany($this->pages->toArray());
        }
    }
577218
public function preFlush(PreFlushEventArgs $args)
    {
        $objectManager = $args->getEntityManager();
        $unitOfWork = $objectManager->getUnitOfWork();

        $entityMap = $unitOfWork->getIdentityMap();
        foreach ($entityMap as $objectClass => $objects) {
            if (in_array(UploadObjectInterface::class, class_implements($objectClass))) {
                foreach ($objects as $object) {
                    $this->prepareUploadFileReferences($object);
                }
            }
        }
    }
66030
public function preFlush(PreFlushEventArgs $event)
    {
        $em = $event->getEntityManager();
        $uow = $em->getUnitOfWork();

        /*
         * We need to use the IdentityMap, because the update and persist collection stores entities, that have
         * computed changes, but translation data might have changed without changing it underlying model!
         */
        foreach($uow->getIdentityMap() as $className) {
            foreach($className as $object) {
                $this->translator->storeTranslationData($object);
            }
        }
    }
1262250
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $classMetadata = $eventArgs->getClassMetadata();
        $reflection = $classMetadata->reflClass;

        if (!$reflection || $reflection->isAbstract()) {
            return;
        }

        if ($reflection->implementsInterface(TranslatableInterface::class)) {
            $this->mapTranslatable($classMetadata);
        }

        if ($reflection->implementsInterface(TranslationInterface::class)) {
            $this->mapTranslation($classMetadata);
        }
    }
1314799
public function preFlush(TranslationInterface $translation, PreFlushEventArgs $event)
    {
        if (null !== $translatable = $translation->getTranslatable()) {
            if (method_exists($translatable, 'setUpdatedAt')) {
                call_user_func([$translatable, 'setUpdatedAt'], new \DateTime());

                $em = $event->getEntityManager();
                $uow = $em->getUnitOfWork();
                $metadata = $em->getClassMetadata(get_class($translatable));
                if ($uow->getEntityChangeSet($translatable)) {
                    $uow->recomputeSingleEntityChangeSet($metadata, $translatable);
                } else {
                    $uow->computeChangeSet($metadata, $translatable);
                }
            }
        }
    }
12357
public function preFlush(PreFlushEventArgs $args)
    {
        $uow = $args->getEntityManager()->getUnitOfWork();
        $result = $uow->getIdentityMap();
        if(isset($result[$this->targetClass])) {
            foreach ($result[$this->targetClass] as $entity) {
                $this->updateEntity($entity);
            }
        }
    }
541545
public function nestedSetPostMove(NestedSetEventArgs $eventArgs)
	{
		$entity = $eventArgs->getEntity();
		$this->em = $eventArgs->getEntityManager();
		$this->unitOfWork = $this->em->getUnitOfWork();

		if ($entity instanceof Page) {
			$changedLocalizations = $this->pageChange($entity, true);

			foreach ($changedLocalizations as $changedLocalization) {
				$this->em->flush($changedLocalization);
			}
		}
	}
1102930
public function preFlush(PreFlushEventArgs $args)
    {
        /** @var object $entity */
        foreach ($args->getEntityManager()->getUnitOfWork()->getScheduledEntityInsertions() as $entity) {
            if (false === in_array(EditableEntityTrait::class, class_uses($entity))) {
                continue;
            }

            if (null === $entity->isDeleted()) {
                $entity->setDeleted(false);
            }

            if (null === $entity->getCreated()) {
                $entity->setCreated(new DateTime());
            }

            if (null === $entity->getUpdated()) {
                $entity->setUpdated(new DateTime());
            }
        }

    }
139036
public function postLoad(LifecycleEventArgs $eventArgs)
    {
        $this->loadTranslation(
            $eventArgs->getEntityManager(),
            $eventArgs->getEntity(),
            $this->getLocale()
        );
    }
796321
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        $entityManager = $eventArgs->getEntityManager();
        $unitOfWork = $entityManager->getUnitOfWork();

        foreach ($unitOfWork->getScheduledEntityInsertions() as $entity) {
            $className = get_class($entity);
            if (isset($this->monitorEntitiesSetting[$className])) {
                $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className];

                if (isset($entityMonitoringConfiguration['events']['created'])) {
                    $data = [];
                    foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) {
                        $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, ['entity' => $entity]);
                    }

                    $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['created'], $data);
                    $unitOfWork->computeChangeSet($entityManager->getClassMetadata(Event::class), $event);
                }
            }
        }

        foreach ($unitOfWork->getScheduledEntityDeletions() as $entity) {
            $className = get_class($entity);
            if (isset($this->monitorEntitiesSetting[$className])) {
                $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className];

                if (isset($entityMonitoringConfiguration['events']['deleted'])) {
                    $data = [];
                    foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) {
                        $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, ['entity' => $entity]);
                    }

                    $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['deleted'], $data);
                    $unitOfWork->computeChangeSet($entityManager->getClassMetadata(Event::class), $event);
                }
            }
        }
    }
379455
public function onFlush(OnFlushEventArgs $args)
    {
        $this->em = $args->getEntityManager();
        $this->uow = $this->em->getUnitOfWork();
        $this->widgetRepo = $this->em->getRepository('Victoire\Bundle\WidgetBundle\Entity\Widget');
        $this->viewRepo = $this->em->getRepository('Victoire\Bundle\CoreBundle\Entity\View');

        $updatedEntities = $this->uow->getScheduledEntityUpdates();
        $deletedEntities = $this->uow->getScheduledEntityDeletions();

        //Update View's CSS and inheritors of updated and deleted widgets
        foreach (array_merge($updatedEntities, $deletedEntities) as $entity) {
            if (!($entity instanceof Widget)) {
                continue;
            }

            /* @var Widget $entity */
            $widgetMap = $entity->getWidgetMap();
            if ($widgetMap->getAction() !== WidgetMap::ACTION_DELETE) {
                $view = $widgetMap->getView();
                if ($this->em->contains($view)) {
                    $this->updateViewCss($view);
                    $this->setTemplateInheritorsCssToUpdate($view);
                }
            }
        }

        //Remove CSS of deleted View and update its inheritors
        foreach ($deletedEntities as $entity) {
            if (!($entity instanceof View)) {
                continue;
            }

            $this->viewCssBuilder->removeCssFile($entity->getCssHash());
            $this->setTemplateInheritorsCssToUpdate($entity);
        }

        //Update CSS of updated View and its inheritors
        foreach ($updatedEntities as $entity) {
            if (!($entity instanceof View)) {
                continue;
            }

            $this->updateViewCss($entity);
            $this->setTemplateInheritorsCssToUpdate($entity);
        }

        $this->uow->computeChangeSets();
    }
415772
public function preFlush(PreFlushEventArgs $args)
    {
        $entityManager = $args->getEntityManager();
        $scheduledInsertions = $entityManager
            ->getUnitOfWork()
            ->getScheduledEntityInsertions();

        $this
            ->categoryIntegrityFixer
            ->fixCategoriesIntegrityByArray($scheduledInsertions);
    }
95597
public function preFlush(EventArgs $eventArgs)
    {
        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();

        foreach ($uow->getScheduledEntityInsertions() as $entity) {
            $this->_triggerEvent(Events::preFlush, $entity, $eventArgs);
        }

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            $this->_triggerEvent(Events::preFlush, $entity, $eventArgs);
        }

        foreach ($uow->getScheduledEntityDeletions() as $entity) {
            $this->_triggerEvent(Events::preFlush, $entity, $eventArgs);
        }
    }