Document/Subscriber/RoutableSubscriber.php
public function handlePublish(PublishEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutableBehavior) {
            return;
        }

        $node = $this->documentInspector->getNode($document);

        try {
            $route = $this->createOrUpdateRoute($document, $event->getLocale());
        } catch (RouteIsNotUniqueException $exception) {
            throw new ResourceLocatorAlreadyExistsException($exception->getRoute()->getPath(), $document->getPath());
        }

        $document->setRoutePath($route->getPath());
        $this->entityManager->persist($route);

        $node->setProperty(
            $this->getRoutePathPropertyName($document->getStructureType(), $event->getLocale()),
            $route->getPath()
        );

        $propertyName = $this->getPropertyName($event->getLocale(), self::ROUTES_PROPERTY);

        // check if nodes previous generated routes exists and remove them if not
        $oldRoutes = $event->getNode()->getPropertyValueWithDefault($propertyName, []);
        $this->removeOldChildRoutes($event->getNode()->getSession(), $oldRoutes, $event->getLocale());

        $routes = [];
        if ($document instanceof ChildrenBehavior) {
            // generate new routes of children
            $routes = $this->generateChildRoutes($document, $event->getLocale());
        }

        // save the newly generated routes of children
        $event->getNode()->setProperty($propertyName, $routes);
        $this->entityManager->flush();
    }
public function handlePublish(PublishEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutableBehavior) {
            return;
        }

        $node = $this->documentInspector->getNode($document);

        try {
            $route = $this->createOrUpdateRoute($document, $event->getLocale());
        } catch (RouteIsNotUniqueException $exception) {
            throw new ResourceLocatorAlreadyExistsException($exception->getRoute()->getPath(), $document->getPath());
        }

        $document->setRoutePath($route->getPath());
        $this->entityManager->persist($route);

        $node->setProperty(
            $this->getRoutePathPropertyName($document->getStructureType(), $event->getLocale()),
            $route->getPath()
        );

        $propertyName = $this->getPropertyName($event->getLocale(), self::ROUTES_PROPERTY);

        // check if nodes previous generated routes exists and remove them if not
        $oldRoutes = $event->getNode()->getPropertyValueWithDefault($propertyName, []);
        $this->removeOldChildRoutes($event->getNode()->getSession(), $oldRoutes, $event->getLocale());

        $routes = [];
        if ($document instanceof ChildrenBehavior) {
            // generate new routes of children
            $routes = $this->generateChildRoutes($document, $event->getLocale());
        }

        // save the newly generated routes of children
        $event->getNode()->setProperty($propertyName, $routes);
        $this->entityManager->flush();
    }
public function handlePublish ( PublishEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ document instanceof RoutableBehavior ) { return ; } $ node = $ this -> documentInspector -> getNode ( $ document ) ; try { $ route = $ this -> createOrUpdateRoute ( $ document , $ event -> getLocale ( ) ) ; } catch ( RouteIsNotUniqueException $ exception ) { throw new ResourceLocatorAlreadyExistsException ( $ exception -> getRoute ( ) -> getPath ( ) , $ document -> getPath ( ) ) ; } $ document -> setRoutePath ( $ route -> getPath ( ) ) ; $ this -> entityManager -> persist ( $ route ) ; $ node -> setProperty ( $ this -> getRoutePathPropertyName ( $ document -> getStructureType ( ) , $ event -> getLocale ( ) ) , $ route -> getPath ( ) ) ; $ propertyName = $ this -> getPropertyName ( $ event -> getLocale ( ) , self :: ROUTES_PROPERTY ) ; // check if nodes previous generated routes exists and remove them if not $ oldRoutes = $ event -> getNode ( ) -> getPropertyValueWithDefault ( $ propertyName , [ ] ) ; $ this -> removeOldChildRoutes ( $ event -> getNode ( ) -> getSession ( ) , $ oldRoutes , $ event -> getLocale ( ) ) ; $ routes = [ ] ; if ( $ document instanceof ChildrenBehavior ) { // generate new routes of children $ routes = $ this -> generateChildRoutes ( $ document , $ event -> getLocale ( ) ) ; } // save the newly generated routes of children $ event -> getNode ( ) -> setProperty ( $ propertyName , $ routes ) ; $ this -> entityManager -> flush ( ) ; }
Handle publish event and generate route and the child-routes.

@param PublishEvent $event

@throws ResourceLocatorAlreadyExistsException
Handle publish event and generate route and the child - routes .