public function onBeforeAddPageCommit(BeforeAddPageCommitEvent $event)
    {
        if ($event->isAborted()) {
            return;
        }

        $pageManager = $event->getContentManager();
        $templateManager = $pageManager->getTemplateManager();
        $pageRepository = $pageManager->getPageRepository();

        try {
            $languages = $this->languageRepository->activeLanguages();
            if (count($languages) > 0) {
                $result = true;
                $templateManager->getBlockRepository()->setConnection($pageRepository->getConnection());
                $pageRepository->startTransaction();
                // The min number of pages is setted to 1 because we are adding a page which has been saved but not
                // committed so it counts as one
                $ignoreRepeatedSlots = $pageManager->getValidator()->hasPages(1);
                $idPage = $pageManager->get()->getId();
                foreach ($languages as $alLanguage) {
                    $result = $templateManager->populate($alLanguage->getId(), $idPage, $ignoreRepeatedSlots);

                    if ($result === false) break;
                }

                if ($result === false) {
                    $pageRepository->rollBack();

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

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

        $pageManager = $event->getContentManager();
        $templateManager = $pageManager->getTemplateManager();
        $pageRepository = $pageManager->getPageRepository();

        try {
            $languages = $this->languageRepository->activeLanguages();
            if (count($languages) > 0) {
                $result = true;
                $templateManager->getBlockRepository()->setConnection($pageRepository->getConnection());
                $pageRepository->startTransaction();
                // The min number of pages is setted to 1 because we are adding a page which has been saved but not
                // committed so it counts as one
                $ignoreRepeatedSlots = $pageManager->getValidator()->hasPages(1);
                $idPage = $pageManager->get()->getId();
                foreach ($languages as $alLanguage) {
                    $result = $templateManager->populate($alLanguage->getId(), $idPage, $ignoreRepeatedSlots);

                    if ($result === false) break;
                }

                if ($result === false) {
                    $pageRepository->rollBack();

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

            throw $e;
        }
    }
public function onBeforeAddPageCommit ( BeforeAddPageCommitEvent $ event ) { if ( $ event -> isAborted ( ) ) { return ; } $ pageManager = $ event -> getContentManager ( ) ; $ templateManager = $ pageManager -> getTemplateManager ( ) ; $ pageRepository = $ pageManager -> getPageRepository ( ) ; try { $ languages = $ this -> languageRepository -> activeLanguages ( ) ; if ( count ( $ languages ) > 0 ) { $ result = true ; $ templateManager -> getBlockRepository ( ) -> setConnection ( $ pageRepository -> getConnection ( ) ) ; $ pageRepository -> startTransaction ( ) ; // The min number of pages is setted to 1 because we are adding a page which has been saved but not // committed so it counts as one $ ignoreRepeatedSlots = $ pageManager -> getValidator ( ) -> hasPages ( 1 ) ; $ idPage = $ pageManager -> get ( ) -> getId ( ) ; foreach ( $ languages as $ alLanguage ) { $ result = $ templateManager -> populate ( $ alLanguage -> getId ( ) , $ idPage , $ ignoreRepeatedSlots ) ; if ( $ result === false ) break ; } if ( $ result === false ) { $ pageRepository -> rollBack ( ) ; $ event -> abort ( ) ; } else { $ pageRepository -> commit ( ) ; } } } catch ( \ Exception $ e ) { $ event -> abort ( ) ; if ( isset ( $ pageRepository ) && $ pageRepository !== null ) { $ pageRepository -> rollBack ( ) ; } throw $ e ; } }
Adds the contents for the page when a new page is added, for each language of the site

@param  \RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Page\BeforeAddPageCommitEvent $event
@return boolean
@throws \Exception

@api
Adds the contents for the page when a new page is added for each language of the site