Document/Serializer/WebsiteArticleUrlsSubscriber.php
public function addUrlsOnPostSerialize(ObjectEvent $event)
    {
        $article = $event->getObject();
        $visitor = $event->getVisitor();
        $context = $event->getContext();
        $request = $this->requestStack->getCurrentRequest();

        if (!$article instanceof ArticleDocument || !$context->attributes->containsKey('website') || !$request) {
            return;
        }

        /** @var RequestAttributes $attributes */
        $attributes = $request->get('_sulu');
        if (!$attributes) {
            return;
        }

        /** @var Webspace $webspace */
        $webspace = $attributes->getAttribute('webspace');
        if (!$webspace) {
            return;
        }

        $urls = [];
        foreach ($webspace->getAllLocalizations() as $localization) {
            $locale = $localization->getLocale();
            $route = $this->routeRepository->findByEntity(get_class($article), $article->getUuid(), $locale);

            $urls[$locale] = '/';
            if ($route) {
                $urls[$locale] = $route->getPath();
            }
        }

        $visitor->addData('urls', $context->accept($urls));
    }
public function addUrlsOnPostSerialize(ObjectEvent $event)
    {
        $article = $event->getObject();
        $visitor = $event->getVisitor();
        $context = $event->getContext();
        $request = $this->requestStack->getCurrentRequest();

        if (!$article instanceof ArticleDocument || !$context->attributes->containsKey('website') || !$request) {
            return;
        }

        /** @var RequestAttributes $attributes */
        $attributes = $request->get('_sulu');
        if (!$attributes) {
            return;
        }

        /** @var Webspace $webspace */
        $webspace = $attributes->getAttribute('webspace');
        if (!$webspace) {
            return;
        }

        $urls = [];
        foreach ($webspace->getAllLocalizations() as $localization) {
            $locale = $localization->getLocale();
            $route = $this->routeRepository->findByEntity(get_class($article), $article->getUuid(), $locale);

            $urls[$locale] = '/';
            if ($route) {
                $urls[$locale] = $route->getPath();
            }
        }

        $visitor->addData('urls', $context->accept($urls));
    }
public function addUrlsOnPostSerialize ( ObjectEvent $ event ) { $ article = $ event -> getObject ( ) ; $ visitor = $ event -> getVisitor ( ) ; $ context = $ event -> getContext ( ) ; $ request = $ this -> requestStack -> getCurrentRequest ( ) ; if ( ! $ article instanceof ArticleDocument || ! $ context -> attributes -> containsKey ( 'website' ) || ! $ request ) { return ; } /** @var RequestAttributes $attributes */ $ attributes = $ request -> get ( '_sulu' ) ; if ( ! $ attributes ) { return ; } /** @var Webspace $webspace */ $ webspace = $ attributes -> getAttribute ( 'webspace' ) ; if ( ! $ webspace ) { return ; } $ urls = [ ] ; foreach ( $ webspace -> getAllLocalizations ( ) as $ localization ) { $ locale = $ localization -> getLocale ( ) ; $ route = $ this -> routeRepository -> findByEntity ( get_class ( $ article ) , $ article -> getUuid ( ) , $ locale ) ; $ urls [ $ locale ] = '/' ; if ( $ route ) { $ urls [ $ locale ] = $ route -> getPath ( ) ; } } $ visitor -> addData ( 'urls' , $ context -> accept ( $ urls ) ) ; }
Loops thru current webspace locales and generates routes for them.

@param ObjectEvent $event
Loops thru current webspace locales and generates routes for them .