public function onFlush(OnFlushEventArgs $args)
    {
        $unit = $args->getEntityManager()->getUnitOfWork();
        $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');


        foreach($unit->getScheduledEntityUpdates() as $entity) {

            if(     $entity instanceof RoutableNodeInterface
                &&  $entity->hasAutoNodeRouteGeneration()
            ) {

                $hasNodeRoute = false;
                $routeGenerated = false;

                foreach ($entity->getRoutes() as $route) {
                    if($route instanceof AutoNodeRoute) {
                        $hasNodeRoute = true;
                        break;
                    }
                }

                if(!$hasNodeRoute) {
                    $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
                    $entity->addRoute($routeManager->generateAutoNodeRoute($entity));
                    $routeGenerated = true;
                }


                // check if Node::name has changed
                $changed = $unit->getEntityChangeSet($entity);

                if(     array_key_exists('name', $changed)
                    ||  array_key_exists('parent', $changed)
                    ||  $routeGenerated
                ) {

                    // update all child AutoNodeRoutes
                    $routeManager->getAutoNodeRoutesRecursive($entity);
                    $unit->computeChangeSets();
                }
            }
        }
    }
public function onFlush(OnFlushEventArgs $args)
    {
        $unit = $args->getEntityManager()->getUnitOfWork();
        $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');


        foreach($unit->getScheduledEntityUpdates() as $entity) {

            if(     $entity instanceof RoutableNodeInterface
                &&  $entity->hasAutoNodeRouteGeneration()
            ) {

                $hasNodeRoute = false;
                $routeGenerated = false;

                foreach ($entity->getRoutes() as $route) {
                    if($route instanceof AutoNodeRoute) {
                        $hasNodeRoute = true;
                        break;
                    }
                }

                if(!$hasNodeRoute) {
                    $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
                    $entity->addRoute($routeManager->generateAutoNodeRoute($entity));
                    $routeGenerated = true;
                }


                // check if Node::name has changed
                $changed = $unit->getEntityChangeSet($entity);

                if(     array_key_exists('name', $changed)
                    ||  array_key_exists('parent', $changed)
                    ||  $routeGenerated
                ) {

                    // update all child AutoNodeRoutes
                    $routeManager->getAutoNodeRoutesRecursive($entity);
                    $unit->computeChangeSets();
                }
            }
        }
    }
public function onFlush ( OnFlushEventArgs $ args ) { $ unit = $ args -> getEntityManager ( ) -> getUnitOfWork ( ) ; $ routeManager = $ this -> container -> get ( 'mm_cmf_routing.node_route_manager' ) ; foreach ( $ unit -> getScheduledEntityUpdates ( ) as $ entity ) { if ( $ entity instanceof RoutableNodeInterface && $ entity -> hasAutoNodeRouteGeneration ( ) ) { $ hasNodeRoute = false ; $ routeGenerated = false ; foreach ( $ entity -> getRoutes ( ) as $ route ) { if ( $ route instanceof AutoNodeRoute ) { $ hasNodeRoute = true ; break ; } } if ( ! $ hasNodeRoute ) { $ routeManager = $ this -> container -> get ( 'mm_cmf_routing.node_route_manager' ) ; $ entity -> addRoute ( $ routeManager -> generateAutoNodeRoute ( $ entity ) ) ; $ routeGenerated = true ; } // check if Node::name has changed $ changed = $ unit -> getEntityChangeSet ( $ entity ) ; if ( array_key_exists ( 'name' , $ changed ) || array_key_exists ( 'parent' , $ changed ) || $ routeGenerated ) { // update all child AutoNodeRoutes $ routeManager -> getAutoNodeRoutesRecursive ( $ entity ) ; $ unit -> computeChangeSets ( ) ; } } } }
onFlush Event for persisting all NodeRoutes that needs an update

@param OnFlushEventArgs $args
onFlush Event for persisting all NodeRoutes that needs an update