Handles actions before creation of an entity.

Sets the module of an entity to the current module defined
by the module manager if it has been left empty.

@param LifecycleEventArgs $args
489036
public function prePersist(LifecycleEventArgs $args)
    {
        $entity        = $args->getEntity();
        $entityManager = $args->getEntityManager();

        $classMetadata = $entityManager->getClassMetadata(get_class($entity));

        if (false == $this->isModular($classMetadata)) {
            return;
        }

        if (null === $entity->getModule() && null !== $this->getModuleManager()->getCurrentModule()) {
            $entity->setModule($this->getModuleManager()->getCurrentModule());
        }
    }
659544
public function postLoad(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();
        $metadata = $this->getTranslatableMetadata(get_class($entity));

        if ($metadata instanceof TranslatableMetadata) {
            if ($metadata->fallbackLocale) {
                $metadata->fallbackLocale->setValue($entity, $this->getFallbackLocale());
            }

            if ($metadata->currentLocale) {
                $metadata->currentLocale->setValue($entity, $this->getCurrentLocale());
            }
        }
    }
454928
public function postUpdate(LifecycleEventArgs $args)
    {
        $object = $args->getObject();

        if (!$object instanceof FileInterface) {
            return;
        }

        // should clear file object also.
        if ($object->isShouldRemove()) {
            $args->getObjectManager()->remove($object);
        }
    }
826928
private function updateViewReference(LifecycleEventArgs $eventArgs)
    {
        $entity = $eventArgs->getEntity();

        //if entity is a translation, get its translatable entity
        if (in_array(Translation::class, class_uses($entity)) && null !== $entity->getTranslatable()) {
            $entity = $entity->getTranslatable();
        }

        //if it's a businessEntity we need to rebuild virtuals (BPs are rebuild in businessEntitySubscriber)
        if ($businessEntity = $this->businessEntityHelper->findByEntityInstance($entity)) {
            $this->flushedBusinessEntities->add($entity);
        }
        //if it a businessTemplate we have to rebuild virtuals or update BP
        if ($entity instanceof BusinessTemplate) {
            $this->flushedBusinessTemplates->add($entity);
        }
    }
904635
public function preFlush(PreFlushEventArgs $args)
    {
        foreach ($args->getEntityManager()->getUnitOfWork()->getScheduledEntityInsertions() as $entity) {
            $this->process($entity);
        }
    }
1178398
public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if (in_array('BespokeSupport\CreatedUpdatedDeletedBundle\Traits\EntityCreatedTrait', class_uses(get_class($entity)))) {
            /**
             * @var $entity \BespokeSupport\CreatedUpdatedDeletedBundle\Traits\EntityCreatedTrait
             */
            if (!$entity->getCreated()) {
                $entity->setCreated(new \DateTime());
            }
        }
    }
230939
public function postRemove(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof MediaInterface) {
            $this->getProvider($args)->postRemove($args->getObject());
        }
    }
205853
public function preTruncate(LifecycleEventArgs $args)
    {
        $connection = $args->getObjectManager()->getConnection();
        $platform   = $connection->getDatabasePlatform();

        if ($platform instanceof MySqlPlatform) {
            $connection->exec('SET foreign_key_checks = 0;');
        }
    }
799349
public function postLoad(Page $page, LifecycleEventArgs $args)
    {
        $hookManager = $this->container->get('mm_cmf_content.page_hook_manager');

        foreach($hookManager->getHooks() as $hook) {
            $hook->process($page, $this->container->get('request_stack')->getCurrentRequest());
        };
    }
27005
public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getObject();

        if ($entity instanceof ContentRoute) {
            $template = $this->templates[$entity->getTemplateName()];

            $entity->setTemplate($template['template']);
            $entity->setController($template['controller']);
        }
    }
1279133
public function postRemove(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof BlockInterface) {
            $this->getService($args)->postRemove($args->getObject());
        }
    }
176838
public function postUpdate(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof BlockInterface) {
            $this->getService($args)->postUpdate($args->getObject());
        }
    }
524491
public function preUpdate(LifecycleEventArgs $args)
    {
        $entity = $args->getObject();
        $em = $args->getObjectManager();
        $uow = $em->getUnitOfWork();

        if ($entity instanceof ContentRoute) {
            $template = $this->templates[$entity->getTemplateName()];
            $changeset = $uow->getEntityChangeSet($entity);
            if (isset($changeset['templateName']) && $args->hasChangedField('templateName')) {
                $entity->setTemplate($template['template']);
                $entity->setController($template['controller']);

                $uow->recomputeSingleEntityChangeSet(
                    $em->getClassMetadata('NetworkingInitCmsBundle:ContentRoute'),
                    $entity
                );
            }
        }
    }
913323
public function postLoad(LifecycleEventArgs $args)
    {
        $object = $args->getObject();
        if(get_class($object) === $this->targetClass) {
            $this->loadEntity($object);
        }
    }
1237954
public function postLoad(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof BlockInterface && !$args->getObject() instanceof DocumentBlock) {
            $this->getService($args)->postLoad($args->getObject());
        }
    }
890109
public function beforePersist(EntityLifecycleEvent $event)
    {
        foreach ($this->getConfiguration() as $entityClassName => $propertyConfiguration) {
            if ($event->getEntity() instanceof $entityClassName) {
                /** @var Repository $repository */
                $entity = $event->getEntity();
                $repository = $event->getRepository();
                foreach ($propertyConfiguration as $propertyName => $configuration) {
                    $this->updateEntity($propertyName, $entity, $repository, $configuration);
                }
            }
        }
    }
1223350
public function preUpdate(LifecycleEventArgs $args): void
    {
        // Get the object and make sure it is what we need.
        $object = $args->getObject();
        if (!$object instanceof PublishableInterface) {
            return;
        }

        // Active unpublished objects should be published.
        if ($object->isActive() && !$object->isPublished()) {
            $object->setPublished(true);
        }
    }