Example #1
0
 public function addRouteCollection(AbstractModule $module, RouteCollection $routeCollection)
 {
     $workflowHelper = new WorkflowUtil(\ServiceUtil::getManager(), \ModUtil::getModule('ZikulaRoutesModule'));
     $routingHelper = new RoutingUtil();
     foreach ($routeCollection->all() as $name => $route) {
         $routeEntity = new RouteEntity();
         $routeEntity->setPath($route->getPath());
         $routeEntity->setDefaults($route->getDefaults());
         $routeEntity->setRequirements($route->getRequirements());
         $routeEntity->setOptions($route->getOptions());
         $routeEntity->setHost($route->getHost());
         $routeEntity->setSchemes($route->getSchemes());
         $routeEntity->setMethods($route->getMethods());
         $routeEntity->setCondition($route->getCondition());
         if ($route->getOption('zkDescription') !== null) {
             $routeEntity->setDescription($route->getOption('zkDescription'));
         }
         $routeEntity->setWorkflowState('approved');
         $routeEntity->setUserRoute(false);
         $position = $route->getOption('zkPosition');
         switch ($position) {
             case 'top':
                 $routeEntity->setGroup(RouteEntity::POSITION_FIXED_TOP);
                 break;
             case 'bottom':
                 $routeEntity->setGroup(RouteEntity::POSITION_FIXED_BOTTOM);
                 break;
             case null:
                 $routeEntity->setGroup(RouteEntity::POSITION_MIDDLE);
                 break;
             default:
                 $dom = \ZLanguage::getModuleDomain('ZikulaRoutesModule');
                 throw new \RuntimeException(__f('Route option "zkPosition" must either be null, "top", or "bottom" for route %s', array($route->getPath()), $dom));
                 break;
         }
         $modname = $module->getName();
         list(, $type, $func, $numericSuffix) = $routingHelper->getParametersFromRouteName($name);
         $routeEntity->setBundle($modname);
         $routeEntity->setController($type);
         $routeEntity->setAction($func);
         $routeEntity->setName(strtolower($modname . "_{$type}" . "_{$func}" . $numericSuffix));
         $workflowHelper->executeAction($routeEntity, 'submit');
     }
 }