public function onBeforeAddLanguageCommit(BeforeAddLanguageCommitEvent $event)
    {
        if ($event->isAborted()) {
            return;
        }

        $this->languageManager = $event->getContentManager();
        $languageRepository = $this->languageManager->getLanguageRepository();

        $this->mainLanguage = $languageRepository->mainLanguage();
        if (null === $this->mainLanguage) {
            $event->abort();

            return;
        }

        $this->sourceObjects = $this->setUpSourceObjects();
        if (count($this->sourceObjects) > 0) {
            try {
                $result = true;
                $languageRepository->startTransaction();
                foreach ($this->sourceObjects as $sourceObject) {
                    $values = $sourceObject->toArray();
                    $result = $this->copy($values);
                    if (!$result) {
                        break;
                    }
                }

                if (false !== $result) {
                    $languageRepository->commit();
                } else {
                    $languageRepository->rollBack();

                    $event->abort();
                }
            } catch (\Exception $e) {
                $event->abort();
                if (isset($languageRepository) && $languageRepository !== null) {
                    $languageRepository->rollBack();
                }

                throw $e;
            }
        }
    }
public function onBeforeAddLanguageCommit(BeforeAddLanguageCommitEvent $event)
    {
        if ($event->isAborted()) {
            return;
        }

        $this->languageManager = $event->getContentManager();
        $languageRepository = $this->languageManager->getLanguageRepository();

        $this->mainLanguage = $languageRepository->mainLanguage();
        if (null === $this->mainLanguage) {
            $event->abort();

            return;
        }

        $this->sourceObjects = $this->setUpSourceObjects();
        if (count($this->sourceObjects) > 0) {
            try {
                $result = true;
                $languageRepository->startTransaction();
                foreach ($this->sourceObjects as $sourceObject) {
                    $values = $sourceObject->toArray();
                    $result = $this->copy($values);
                    if (!$result) {
                        break;
                    }
                }

                if (false !== $result) {
                    $languageRepository->commit();
                } else {
                    $languageRepository->rollBack();

                    $event->abort();
                }
            } catch (\Exception $e) {
                $event->abort();
                if (isset($languageRepository) && $languageRepository !== null) {
                    $languageRepository->rollBack();
                }

                throw $e;
            }
        }
    }
public function onBeforeAddLanguageCommit ( BeforeAddLanguageCommitEvent $ event ) { if ( $ event -> isAborted ( ) ) { return ; } $ this -> languageManager = $ event -> getContentManager ( ) ; $ languageRepository = $ this -> languageManager -> getLanguageRepository ( ) ; $ this -> mainLanguage = $ languageRepository -> mainLanguage ( ) ; if ( null === $ this -> mainLanguage ) { $ event -> abort ( ) ; return ; } $ this -> sourceObjects = $ this -> setUpSourceObjects ( ) ; if ( count ( $ this -> sourceObjects ) > 0 ) { try { $ result = true ; $ languageRepository -> startTransaction ( ) ; foreach ( $ this -> sourceObjects as $ sourceObject ) { $ values = $ sourceObject -> toArray ( ) ; $ result = $ this -> copy ( $ values ) ; if ( ! $ result ) { break ; } } if ( false !== $ result ) { $ languageRepository -> commit ( ) ; } else { $ languageRepository -> rollBack ( ) ; $ event -> abort ( ) ; } } catch ( \ Exception $ e ) { $ event -> abort ( ) ; if ( isset ( $ languageRepository ) && $ languageRepository !== null ) { $ languageRepository -> rollBack ( ) ; } throw $ e ; } } }
Listen the onBeforeAddLanguageCommit event to copy the source object to the new language

@param  BeforeAddLanguageCommitEvent $event
@return boolean
@throws \Exception

@api
Listen the onBeforeAddLanguageCommit event to copy the source object to the new language