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

        $pageManager = $event->getContentManager();
        $pageRepository = $pageManager->getPageRepository();
        $values = $event->getValues();

        if (!is_array($values)) {
            throw new InvalidArgumentException('exception_invalid_value_array_required');
        }

        try {
            $languages = $this->languageRepository->activeLanguages();
            if (count($languages)) {
                $result = true;
                $idPage = $pageManager->get()->getId();
                $this->seoManager->getSeoRepository()->setConnection($pageRepository->getConnection());
                $pageRepository->startTransaction();
                foreach ($languages as $alLanguage) {
                    $seoManagerValues = array_merge($values, array('PageId' => $idPage, 'LanguageId' => $alLanguage->getId(), 'CreatedAt'       => date("Y-m-d H:i:s")));
                    if (!$alLanguage->getMainLanguage() && array_key_exists('Permalink', $seoManagerValues)) $seoManagerValues['Permalink'] = $alLanguage->getLanguageName() . '-' . $seoManagerValues['Permalink'];
                    $this->seoManager->set(null);
                    $result = $this->seoManager->save($seoManagerValues);

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

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

                    return;
                }

                $pageRepository->rollBack();
                $event->abort();
            }
        } 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();
        $pageRepository = $pageManager->getPageRepository();
        $values = $event->getValues();

        if (!is_array($values)) {
            throw new InvalidArgumentException('exception_invalid_value_array_required');
        }

        try {
            $languages = $this->languageRepository->activeLanguages();
            if (count($languages)) {
                $result = true;
                $idPage = $pageManager->get()->getId();
                $this->seoManager->getSeoRepository()->setConnection($pageRepository->getConnection());
                $pageRepository->startTransaction();
                foreach ($languages as $alLanguage) {
                    $seoManagerValues = array_merge($values, array('PageId' => $idPage, 'LanguageId' => $alLanguage->getId(), 'CreatedAt'       => date("Y-m-d H:i:s")));
                    if (!$alLanguage->getMainLanguage() && array_key_exists('Permalink', $seoManagerValues)) $seoManagerValues['Permalink'] = $alLanguage->getLanguageName() . '-' . $seoManagerValues['Permalink'];
                    $this->seoManager->set(null);
                    $result = $this->seoManager->save($seoManagerValues);

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

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

                    return;
                }

                $pageRepository->rollBack();
                $event->abort();
            }
        } 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 ( ) ; $ pageRepository = $ pageManager -> getPageRepository ( ) ; $ values = $ event -> getValues ( ) ; if ( ! is_array ( $ values ) ) { throw new InvalidArgumentException ( 'exception_invalid_value_array_required' ) ; } try { $ languages = $ this -> languageRepository -> activeLanguages ( ) ; if ( count ( $ languages ) ) { $ result = true ; $ idPage = $ pageManager -> get ( ) -> getId ( ) ; $ this -> seoManager -> getSeoRepository ( ) -> setConnection ( $ pageRepository -> getConnection ( ) ) ; $ pageRepository -> startTransaction ( ) ; foreach ( $ languages as $ alLanguage ) { $ seoManagerValues = array_merge ( $ values , array ( 'PageId' => $ idPage , 'LanguageId' => $ alLanguage -> getId ( ) , 'CreatedAt' => date ( "Y-m-d H:i:s" ) ) ) ; if ( ! $ alLanguage -> getMainLanguage ( ) && array_key_exists ( 'Permalink' , $ seoManagerValues ) ) $ seoManagerValues [ 'Permalink' ] = $ alLanguage -> getLanguageName ( ) . '-' . $ seoManagerValues [ 'Permalink' ] ; $ this -> seoManager -> set ( null ) ; $ result = $ this -> seoManager -> save ( $ seoManagerValues ) ; if ( false === $ result ) break ; } if ( false !== $ result ) { $ pageRepository -> commit ( ) ; return ; } $ pageRepository -> rollBack ( ) ; $ event -> abort ( ) ; } } catch ( \ Exception $ e ) { $ event -> abort ( ) ; if ( isset ( $ pageRepository ) && $ pageRepository !== null ) { $ pageRepository -> rollBack ( ) ; } throw $ e ; } }
Adds the page's seo attributes when a new page is added, for each language of
the site

@param  BeforeAddPageCommitEvent $event
@return boolean
@throws InvalidArgumentException
@throws \Exception

@api
Adds the page s seo attributes when a new page is added for each language of the site