original_string: 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();
                  }
              }
          }
      }
code: 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();
                  }
              }
          }
      }
code_tokens: 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 ( ) ; } } } }
docstring: onFlush Event for persisting all NodeRoutes that needs an update
  
  @param OnFlushEventArgs $args
docstring_tokens: onFlush Event for persisting all NodeRoutes that needs an update