Author: david.buchmann@liip.ch
Inheritance: extends Symfony\Cmf\Bundle\RoutingBundle\Model\Route, implements Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\PrefixInterface, implements Doctrine\ODM\PHPCR\HierarchyInterface
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager|DocumentManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $contentParent = $manager->find(null, '/cms/content');
     $routeParent = $manager->find(null, '/cms/routes/en/services');
     $menuBase = $manager->find(null, '/cms/menu/footer');
     $content = new DemoSeoContent();
     $content->setParentDocument($contentParent);
     $content->setName('seo-service');
     $content->setTitle('SEO Service');
     $content->setBody('A page about SEO service');
     $metaData = new SeoMetadata();
     $metaData->setMetaDescription('Description in Metadata');
     $content->setSeoMetadata($metaData);
     $manager->persist($content);
     $manager->bindTranslation($content, 'en');
     $contentRoute = new Route();
     $contentRoute->setParentDocument($routeParent);
     $contentRoute->setName('seo-service');
     $contentRoute->setContent($content);
     $manager->persist($contentRoute);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menuBase);
     $menuNode->setName('seo-service');
     $menuNode->setLabel('SEO Services');
     $menuNode->setContent($content);
     $manager->persist($menuNode);
     $manager->flush();
 }
 public function testOutside()
 {
     $this->routeMock->expects($this->exactly(2))->method('getId')->will($this->returnValue('/outside'));
     $this->routeMock->expects($this->never())->method('setPrefix');
     $args = new LifecycleEventArgs($this->routeMock, $this->dmMock);
     $this->listener->postLoad($args);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $session = $manager->getPhpcrSession();
     $basepath = $this->container->getParameter('cmf_routing.dynamic.persistence.phpcr.route_basepath');
     NodeHelper::createPath($session, $basepath);
     $routeRoot = $manager->find(null, $basepath);
     $basepath = $this->container->getParameter('cmf_content.persistence.phpcr.content_basepath');
     NodeHelper::createPath($session, $basepath);
     $parent = $manager->find(null, $basepath);
     $repository = $this->container->get('sylius.repository.page');
     // Terms of service.
     $route = new Route();
     $route->setPosition($routeRoot, 'terms-of-service');
     $manager->persist($route);
     $content = $repository->createNew();
     $content->setTitle('Terms of Service');
     $content->setBody($this->faker->text(350));
     $content->addRoute($route);
     $content->setParent($parent);
     $content->setName('terms-of-service');
     $manager->persist($content);
     // Contact.
     $route = new Route();
     $route->setPosition($routeRoot, 'about');
     $manager->persist($route);
     $content = $repository->createNew();
     $content->setTitle('About us');
     $content->setBody($this->faker->text(300));
     $content->addRoute($route);
     $content->setParent($parent);
     $content->setName('about-us');
     $manager->persist($content);
     $manager->flush();
 }
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/content');
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes/content');
     $contentRoot = $manager->find(null, '/test/content');
     $routeRoot = $manager->find(null, '/test/routes/content');
     $content = new SeoAwareContent();
     $content->setName('content-1');
     $content->setTitle('Content 1');
     $content->setBody('Content 1');
     $content->setParentDocument($contentRoot);
     $metadata = new SeoMetadata();
     $metadata->setTitle('Title content 1');
     $metadata->setMetaDescription('Description of content 1.');
     $metadata->setMetaKeywords('content1, content');
     $metadata->setOriginalUrl('/to/original');
     $content->setSeoMetadata($metadata);
     $manager->persist($content);
     $route = new Route();
     $route->setPosition($routeRoot, 'content-1');
     $route->setContent($content);
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction');
     $manager->persist($route);
     $manager->persist($route);
     $manager->flush();
 }
Ejemplo n.º 5
0
 private function createPageRoute($pageTitle)
 {
     $route = new Route();
     $route->setParentDocument($this->getModelManager()->find(null, '/cms/londa/routes'));
     //@TODO Get route path from configs
     $route->setName(Slugger::slugify($pageTitle));
     return $route;
 }
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager|DocumentManager $manager
  */
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/cms/routes');
     $routeBase = $manager->find(null, '/cms/routes');
     $route = new Route();
     $route->setPosition($routeBase, 'route_only');
     $route->addDefaults(['_controller' => 'froscon_application.controller.default:routeOnlyAction']);
     $manager->persist($route);
     $manager->flush();
 }
Ejemplo n.º 7
0
 /**
  * @param string $path
  *
  * @return Route
  */
 protected function createRoute($path)
 {
     $parentPath = PathHelper::getParentPath($path);
     $parent = $this->getDm()->find(null, $parentPath);
     $name = PathHelper::getNodeName($path);
     $route = new Route();
     $route->setPosition($parent, $name);
     $this->getDm()->persist($route);
     $this->getDm()->flush();
     return $route;
 }
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager|DocumentManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $contentParent = $manager->find(null, '/cms/content');
     $routeParent = $manager->find(null, '/cms/routes');
     $menuBase = $manager->find(null, '/cms/menu');
     $enRoute = new Route();
     $enRoute->setPosition($routeParent, 'en');
     $manager->persist($enRoute);
     $deRoute = new Route();
     $deRoute->setPosition($routeParent, 'de');
     $manager->persist($deRoute);
     $enServiceRoute = new Route();
     $enServiceRoute->setPosition($enRoute, 'services');
     $manager->persist($enServiceRoute);
     $deServiceRoute = new Route();
     $deServiceRoute->setPosition($deRoute, 'dienstleistungen');
     $manager->persist($deServiceRoute);
     $content = new StaticContent();
     $content->setParentDocument($contentParent);
     $content->setName('symfony-service');
     $manager->persist($content);
     $content->setTitle('Symfony Service');
     $content->setBody('A page about Symfony service');
     $manager->bindTranslation($content, 'en');
     $contentRoute = new Route();
     $contentRoute->setPosition($enServiceRoute, 'symfony-service');
     $contentRoute->setContent($content);
     $manager->persist($contentRoute);
     $content->setTitle('Symfony Dienstleistungen');
     $content->setBody('Eine Seite über Symfony Dienstleistungen');
     $manager->bindTranslation($content, 'de');
     $contentRoute = new Route();
     $contentRoute->setPosition($deServiceRoute, 'symfony-dienstleistungen');
     $contentRoute->setContent($content);
     $manager->persist($contentRoute);
     $menu = new Menu();
     $menu->setPosition($menuBase, 'footer');
     $manager->persist($menu);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setContent($content);
     $menuNode->setName('symfony-service');
     $manager->persist($menuNode);
     $menuNode->setLabel('Symfony Services');
     $manager->bindTranslation($menuNode, 'en');
     $menuNode->setLabel('Symfony Dienstleistungen');
     $manager->bindTranslation($menuNode, 'de');
     $manager->flush();
 }
Ejemplo n.º 9
0
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     $root = $manager->find(null, '/test');
     $parent = new Generic();
     $parent->setParent($root);
     $parent->setNodename('routing');
     $manager->persist($parent);
     $route = new Route();
     $route->setParentDocument($parent);
     $route->setName('route-1');
     $manager->persist($route);
     $redirectRoute = new RedirectRoute();
     $redirectRoute->setParentDocument($parent);
     $redirectRoute->setName('redirect-route-1');
     $manager->persist($redirectRoute);
     $manager->flush();
 }
Ejemplo n.º 10
0
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/content');
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes');
     $contentRoot = $manager->find(null, '/test/content');
     $routeRoot = $manager->find(null, '/test/routes');
     $sitemapAwareContent = new SitemapAwareContent();
     $sitemapAwareContent->setIsVisibleForSitemap(true)->setTitle('Sitemap Aware Content')->setName('sitemap-aware')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware');
     $manager->persist($sitemapAwareContent);
     $manager->bindTranslation($sitemapAwareContent, 'en');
     $sitemapAwareContent->setTitle('Content für die Sitemap')->setBody('Das sollte die Deutsche Version des Contents sein.');
     $manager->bindTranslation($sitemapAwareContent, 'de');
     $route = new Route();
     $route->setPosition($routeRoot, 'sitemap-aware');
     $route->setContent($sitemapAwareContent);
     $manager->persist($route);
     $nonPublishedContent = new SitemapAwareWithPublishWorkflowContent();
     $nonPublishedContent->setIsVisibleForSitemap(true);
     $nonPublishedContent->setPublishable(false);
     $nonPublishedContent->setTitle('Sitemap Aware Content non publish')->setName('sitemap-aware-non-publish')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware, that is not publish');
     $manager->persist($nonPublishedContent);
     $route = new Route();
     $route->setPosition($routeRoot, 'sitemap-aware-non-publish');
     $route->setContent($nonPublishedContent);
     $manager->persist($route);
     $publishedContent = new SitemapAwareWithPublishWorkflowContent();
     $publishedContent->setIsVisibleForSitemap(true);
     $publishedContent->setPublishable(true);
     $publishedContent->setTitle('Sitemap Aware Content publish')->setName('sitemap-aware-publish')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware, that is publish');
     $manager->persist($publishedContent);
     $route = new Route();
     $route->setPosition($routeRoot, 'sitemap-aware-publish');
     $route->setContent($publishedContent);
     $manager->persist($route);
     $lastModifiedContent = new SitemapAwareWithLastModifiedDateContent();
     $lastModifiedContent->setIsVisibleForSitemap(true)->setLastModified(new \DateTime('2016-07-06', new \DateTimeZone('Europe/Berlin')))->setTitle('Sitemap Aware Content last mod date')->setName('sitemap-aware-last-mod-date')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware, that has last modified date.');
     $manager->persist($lastModifiedContent);
     $route = new Route();
     $route->setPosition($routeRoot, 'sitemap-aware-last-mod-date');
     $route->setContent($lastModifiedContent);
     $manager->persist($route);
     $manager->flush();
 }
Ejemplo n.º 11
0
 private function buildRoutes()
 {
     $root = $this->getDm()->find(null, self::ROUTE_ROOT);
     $route = new Route();
     $route->setPosition($root, 'testroute');
     $route->setDefault('_format', 'html');
     $this->getDm()->persist($route);
     // smuggle a non-route thing into the repository
     $noroute = new Generic();
     $noroute->setParentDocument($route);
     $noroute->setNodename('noroute');
     $this->getDm()->persist($noroute);
     $childroute = new Route();
     $childroute->setPosition($noroute, 'child');
     $childroute->setDefault('_format', 'json');
     $this->getDm()->persist($childroute);
     $this->getDm()->flush();
     $this->getDm()->clear();
 }
Ejemplo n.º 12
0
 /**
  * URL without locale, set available translations.
  */
 public function testAvailableTranslations()
 {
     $this->routeMock->expects($this->once())->method('getId')->will($this->returnValue('/cms/simple/something'));
     $this->dmMock->expects($this->once())->method('isDocumentTranslatable')->with($this->routeMock)->will($this->returnValue(true));
     $this->dmMock->expects($this->once())->method('getLocalesFor')->with($this->routeMock, true)->will($this->returnValue(array('en', 'de', 'fr')));
     $this->routeMock->expects($this->once())->method('setRequirement')->with('_locale', 'en|de|fr');
     $this->listener->setUpdateAvailableTranslations(true);
     $args = new LifecycleEventArgs($this->routeMock, $this->dmMock);
     $this->listener->postLoad($args);
 }
Ejemplo n.º 13
0
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     $root = $manager->find(null, '/test');
     $parent = new Generic();
     $parent->setParentDocument($root);
     $parent->setNodename('routing');
     $manager->persist($parent);
     $routeCollection = new Route();
     $routeCollection->setParentDocument($parent);
     $routeCollection->setMethods(array('POST', 'GET', 'PUT'));
     # Todo check if we can add a type and set defaults prePersist?
     $routeCollection->setName('collection');
     $manager->persist($routeCollection);
     $route = new Route();
     $route->setParentDocument($routeCollection);
     $route->setName('get-1');
     $route->setMethods(array(Request::METHOD_GET));
     $manager->persist($route);
     $route = new Route();
     $route->setParentDocument($routeCollection);
     $route->setName('post-1');
     $route->setMethods(array(Request::METHOD_POST));
     $manager->persist($route);
     $route = new Route();
     $route->setParentDocument($routeCollection);
     $route->setName('put-1');
     $route->setMethods(array(Request::METHOD_PUT));
     $manager->persist($route);
     $route = new Route();
     $route->setParentDocument($routeCollection);
     $route->setName('delete-1');
     $route->setMethods(array(Request::METHOD_DELETE));
     $manager->persist($route);
     $route = new Route();
     $route->setParentDocument($routeCollection);
     $route->setName('patch-1');
     $route->setMethods(array(Request::METHOD_PATCH));
     $manager->persist($route);
     $manager->flush();
 }
Ejemplo n.º 14
0
 public function testRedirectContent()
 {
     $content = $this->createContent();
     $root = $this->getDm()->find(null, self::ROUTE_ROOT);
     $route = new Route();
     $route->setContent($content);
     $route->setPosition($root, 'testroute');
     $this->getDm()->persist($route);
     $redirect = new RedirectRoute();
     $redirect->setPosition($root, 'redirectContent');
     $redirect->setRouteTarget($route);
     $redirect->setParameters(array('test' => 'content'));
     $this->getDm()->persist($redirect);
     $this->getDm()->flush();
     $this->getDm()->clear();
     $redirect = $this->getDm()->find(null, self::ROUTE_ROOT . '/redirectContent');
     $response = $this->controller->redirectAction($redirect);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     $this->assertSame(302, $response->getStatusCode());
     $this->assertSame('http://localhost/testroute?test=content', $response->getTargetUrl());
 }
Ejemplo n.º 15
0
 public function load(ObjectManager $manager)
 {
     $root = $manager->find(null, '/');
     $test = new Generic();
     $test->setNodename('test');
     $test->setParentDocument($root);
     $manager->persist($test);
     $content = new Generic();
     $content->setNodename('content');
     $content->setParentDocument($test);
     $manager->persist($content);
     $aContent = new Content();
     $aContent->id = '/test/content/a';
     $manager->persist($aContent);
     $bContent = new Content();
     $bContent->id = '/test/content/b';
     $manager->persist($bContent);
     $cms = new Generic();
     $cms->setNodename('cms');
     $cms->setParentDocument($test);
     $manager->persist($cms);
     $routes = new Generic();
     $routes->setNodename('routes');
     $routes->setParentDocument($cms);
     $manager->persist($routes);
     $aRoute = new Route();
     $aRoute->setName('a');
     $aRoute->setParentDocument($routes);
     $aRoute->setContent($aContent);
     $manager->persist($aRoute);
     $bRoute = new Route();
     $bRoute->setName('b');
     $bRoute->setParentDocument($routes);
     $bRoute->setContent($bContent);
     $manager->persist($bRoute);
     $manager->flush();
 }
Ejemplo n.º 16
0
 public function testRedirectDoctrine()
 {
     $content = $this->createContent();
     $root = $this->getDm()->find(null, self::ROUTE_ROOT);
     $route = new Route();
     $route->setContent($content);
     $route->setPosition($root, 'testroute');
     $this->getDm()->persist($route);
     $redirect = new RedirectRoute();
     $redirect->setPosition($root, 'redirect');
     $redirect->setRouteTarget($route);
     $redirect->setDefault('test', 'toast');
     $this->getDm()->persist($redirect);
     $this->getDm()->flush();
     $this->getDm()->clear();
     $route = $this->getDm()->find(null, self::ROUTE_ROOT . '/testroute');
     $redirect = $this->getDm()->find(null, self::ROUTE_ROOT . '/redirect');
     $this->assertInstanceOf('Symfony\\Cmf\\Component\\Routing\\RedirectRouteInterface', $redirect);
     $this->assertSame($redirect, $redirect->getContent());
     $params = $redirect->getParameters();
     $this->assertSame($route, $redirect->getRouteTarget());
     $defaults = $redirect->getDefaults();
     $this->assertEquals(array('test' => 'toast'), $defaults);
 }
 /**
  * Creates pages and their corresponding routes & menu entries
  * @param  ObjectManager $this->documentManager PHPCR ODM DocumentManager instance
  */
 private function createLondaPages()
 {
     //the menus
     $mainMenu = $this->createMenus();
     $pages = Yaml::parse(file_get_contents(__DIR__ . '/../../Resources/data/pages.yml'));
     //Create the pages and their corresponding routes and menu nodes
     foreach ($pages["KanzuCode\\LondaBundle\\Document\\Page"] as $pageId => $page) {
         //Define the route
         $route = new Route();
         $route->setParentDocument($this->documentManager->find(null, $this->config['parameters']['londa.basepath.routes']));
         $route->setName($page['route']);
         if (isset($page['template'])) {
             $route->setDefault('_template', "KanzuCodeLondaBundle:Default:{$page['template']}.html.twig");
         }
         if (isset($page['controller'])) {
             $route->setDefault('_controller', "KanzuCodeLondaBundle:LondaContent:{$page['controller']}");
         }
         $this->documentManager->persist($route);
         // add the route
         //Add menu node
         $menuNode = new MenuNode();
         $menuNode->setName($pageId);
         $menuNode->setLabel($page['title']);
         $menuNode->setParentDocument($mainMenu);
         $this->documentManager->persist($menuNode);
         //Do the content
         $content = new Page();
         $content->setParentDocument($this->documentManager->find(null, $this->config['parameters']['londa.basepath.pages']));
         $content->setName($pageId);
         $content->setTitle($page['title']);
         $content->setBody($page['body']);
         $content->addRoute($route);
         $content->addMenuNode($menuNode);
         $this->documentManager->persist($content);
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->createDate = new \DateTime();
     $this->containerBlocks = new ArrayCollection();
 }
Ejemplo n.º 19
0
 public function testEnhanceTemplateByClass()
 {
     if ($content = $this->getDm()->find(null, '/test/content/templatebyclass')) {
         $this->getDm()->remove($content);
         $this->getDm()->flush();
     }
     NodeHelper::createPath($this->getDm()->getPhpcrSession(), '/test/content');
     $document = new Content();
     $document->setId('/test/content/templatebyclass');
     $document->setTitle('the title');
     $this->getDm()->persist($document);
     // put a route for this content
     $root = $this->getDm()->find(null, self::ROUTE_ROOT);
     $route = new Route();
     $route->setContent($document);
     $route->setPosition($root, 'templatebyclass');
     $this->getDm()->persist($route);
     $this->getDm()->flush();
     $expected = array('_controller' => 'cmf_content.controller:indexAction', RouteObjectInterface::ROUTE_NAME => self::ROUTE_ROOT . '/templatebyclass');
     $request = Request::create('/templatebyclass');
     $matches = $this->router->matchRequest($request);
     ksort($matches);
     $this->assertEquals($expected, $matches);
     $this->assertTrue($request->attributes->has(DynamicRouter::ROUTE_KEY));
     $this->assertTrue($request->attributes->has(DynamicRouter::CONTENT_TEMPLATE));
     $this->assertEquals('TestBundle:Content:index.html.twig', $request->attributes->get(DynamicRouter::CONTENT_TEMPLATE));
 }
Ejemplo n.º 20
0
 /**
  * Load routing data into the document manager.
  *
  * NOTE: We demo all possibilities. Of course, you should try to be
  * consistent in what you use and only use different things for special
  * cases.
  *
  * @param $manager \Doctrine\ODM\PHPCR\DocumentManager
  */
 public function load(ObjectManager $manager)
 {
     if (!$manager instanceof DocumentManager) {
         $class = get_class($manager);
         throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '{$class}' given.");
     }
     $session = $manager->getPhpcrSession();
     $basepath = $this->container->getParameter('cmf_routing.dynamic.persistence.phpcr.admin_basepath');
     if ($session->itemExists($basepath)) {
         $session->removeItem($basepath);
     }
     NodeHelper::createPath($session, $basepath);
     $parent = $manager->find(null, $basepath);
     $content_path = $this->container->getParameter('cmf_content.persistence.phpcr.content_basepath');
     $locales = $this->container->getParameter('locales');
     foreach ($locales as $locale) {
         $home = new Route();
         $home->setPosition($parent, $locale);
         $home->setDefault(RouteObjectInterface::TEMPLATE_NAME, 'homepage/index.html.twig');
         $home->setContent($manager->find(null, "{$content_path}/home"));
         $manager->persist($home);
         $company = new Route();
         $company->setPosition($home, 'company');
         $company->setContent($manager->find(null, "{$content_path}/company"));
         $manager->persist($company);
         $team = new Route();
         $team->setPosition($company, 'team');
         $team->setContent($manager->find(null, "{$content_path}/team"));
         $manager->persist($team);
         $more = new Route();
         $more->setPosition($company, 'more');
         $more->setContent($manager->find(null, "{$content_path}/more"));
         $manager->persist($more);
         $projects = new Route();
         $projects->setPosition($home, 'projects');
         $projects->setContent($manager->find(null, "{$content_path}/projects"));
         $manager->persist($projects);
         $cmf = new Route();
         $cmf->setPosition($projects, 'cmf');
         $cmf->setContent($manager->find(null, "{$content_path}/cmf"));
         $manager->persist($cmf);
         $seo = new Route();
         $seo->setPosition($home, 'simple-seo-example');
         $seo->setContent($manager->find(null, "{$content_path}/simple-seo-example"));
         $manager->persist($seo);
         $seo = new Route();
         $seo->setPosition($home, 'simple-seo-property');
         $seo->setContent($manager->find(null, "{$content_path}/simple-seo-property"));
         $manager->persist($seo);
         $seo = new Route();
         $seo->setPosition($home, 'demo-seo-extractor');
         $seo->setContent($manager->find(null, "{$content_path}/demo-seo-extractor"));
         $manager->persist($seo);
     }
     // demo features of routing
     // we can create routes without locales, but will lose the language context of course
     $demo = new Route();
     $demo->setPosition($parent, 'demo');
     $demo->setContent($manager->find(null, "{$content_path}/demo"));
     $demo->setDefault(RouteObjectInterface::TEMPLATE_NAME, 'demo/template_explicit.html.twig');
     $manager->persist($demo);
     // explicit template
     $template = new Route();
     $template->setPosition($demo, 'atemplate');
     $template->setContent($manager->find(null, "{$content_path}/demo_template"));
     $template->setDefault(RouteObjectInterface::TEMPLATE_NAME, 'demo/template_explicit.html.twig');
     $manager->persist($template);
     // explicit controller
     $controller = new Route();
     $controller->setPosition($demo, 'controller');
     $controller->setContent($manager->find(null, "{$content_path}/demo_controller"));
     $controller->setDefault('_controller', 'app.content_controller:specialAction');
     $manager->persist($controller);
     // type to controller mapping
     $type = new Route();
     $type->setPosition($demo, 'type');
     $type->setContent($manager->find(null, "{$content_path}/demo_type"));
     $type->setDefault('type', 'demo_type');
     $manager->persist($type);
     // class to controller mapping
     $class = new Route();
     $class->setPosition($demo, 'class');
     $class->setContent($manager->find(null, "{$content_path}/demo_class"));
     $manager->persist($class);
     // redirections
     // redirect to uri
     $redirect = new RedirectRoute();
     $redirect->setPosition($parent, 'external');
     $redirect->setUri('http://cmf.symfony.com');
     $manager->persist($redirect);
     // redirect to other doctrine route
     $redirectRoute = new RedirectRoute();
     $redirectRoute->setPosition($parent, 'short');
     $redirectRoute->setRouteTarget($cmf);
     $manager->persist($redirectRoute);
     // redirect to Symfony route
     $redirectS = new RedirectRoute();
     $redirectS->setPosition($parent, 'short1');
     $redirectS->setRouteName('test');
     $manager->persist($redirectS);
     // class to template mapping is used for all the rest
     $default_locale = $this->container->getParameter('locale');
     $singlelocale = new Route();
     $singlelocale->setPosition($manager->find(null, "{$basepath}/{$default_locale}"), 'singlelocale');
     $singlelocale->setDefault('_locale', $default_locale);
     $singlelocale->setRequirement('_locale', $default_locale);
     $singlelocale->setContent($manager->find(null, "{$content_path}/singlelocale"));
     $manager->persist($singlelocale);
     // publication demos
     $publicationDemo = new Route();
     $publicationDemo->setPosition($parent, 'publicationdemo');
     $publicationDemo->setContent($manager->find(null, "{$content_path}/publication_demo"));
     $manager->persist($publicationDemo);
     $notPublished = new Route();
     $notPublished->setPosition($publicationDemo, 'notpublished');
     $notPublished->setContent($manager->find(null, "{$content_path}/not_published"));
     $manager->persist($notPublished);
     $publishedTomorrow = new Route();
     $publishedTomorrow->setPosition($publicationDemo, 'publishedtomorrow');
     $publishedTomorrow->setContent($manager->find(null, "{$content_path}/published_tomorrow"));
     $manager->persist($publishedTomorrow);
     $manager->flush();
 }
Ejemplo n.º 21
0
 protected function loadMenu(DocumentManager $manager)
 {
     $route = new Route();
     $route->setName('content-1');
     $route->setParentDocument($this->routeRoot);
     $manager->persist($route);
     $content = new Content();
     $content->setTitle('Menu Item Content 1');
     $content->setId('/test/content-menu-item-1');
     $content->addRoute($route);
     $menu = new Menu();
     $menu->setName('test-menu');
     $menu->setLabel('Test Menu');
     $menu->setParentDocument($this->menuRoot);
     $manager->persist($menu);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('item-1');
     $menuNode->setName('item-1');
     $manager->persist($menuNode);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('This node has a URI');
     $menuNode->setUri('http://www.example.com');
     $menuNode->setName('item-2');
     $manager->persist($menuNode);
     $subNode = new MenuNode();
     $subNode->setParentDocument($menuNode);
     $subNode->setLabel('This node has content');
     $subNode->setName('sub-item-1');
     $subNode->setContent($content);
     $manager->persist($subNode);
     $content->addMenuNode($subNode);
     $subNode = new MenuNode();
     $subNode->setParentDocument($menuNode);
     $subNode->setLabel('This node has an assigned route');
     $subNode->setName('sub-item-2');
     $subNode->setRoute('link_test_route');
     $manager->persist($subNode);
     $subNode = new MenuNode();
     $subNode->setParentDocument($menuNode);
     $subNode->setLabel('This node has an assigned route with parameters');
     $subNode->setName('sub-item-3');
     $subNode->setRoute('link_test_route_with_params');
     $subNode->setRouteParameters(array('foo' => 'bar', 'bar' => 'foo'));
     $manager->persist($subNode);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('item-3');
     $menuNode->setName('item-3');
     $manager->persist($menuNode);
     $menu = new Menu();
     $menu->setName('another-menu');
     $menu->setLabel('Another Menu');
     $menu->setParentDocument($this->menuRoot);
     $manager->persist($menu);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('This node has uri, route and content set. but linkType is set to route');
     $menuNode->setLinkType('route');
     $menuNode->setUri('http://www.example.com');
     $menuNode->setRoute('link_test_route');
     $menuNode->setName('item-1');
     $manager->persist($menuNode);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('item-2');
     $menuNode->setName('item-2');
     $manager->persist($menuNode);
     $manager->persist($content);
 }
Ejemplo n.º 22
0
 public function testDefaultFormat()
 {
     $route = new Route(array('add_format_pattern' => true));
     $root = $this->getDm()->find(null, self::ROUTE_ROOT);
     $route->setPosition($root, 'format');
     $this->getDm()->persist($route);
     $this->getDm()->flush();
     $this->getDm()->clear();
     $route = $this->getDm()->find(null, self::ROUTE_ROOT . '/format');
     $this->assertEquals('/format.{_format}', $route->getPath());
 }
Ejemplo n.º 23
0
 /**
  * Update the locale of a route if $id starts with the prefix and has a
  * valid locale right after.
  *
  * @param Route           $doc   The route object
  * @param string          $id    The id (in move case, this is not the current
  *                               id of $route).
  * @param DocumentManager $dm    The document manager to get locales from if
  *                               the setAvailableTranslations option is
  *                               enabled.
  * @param boolean         $force Whether to update the locale even if the
  *                               route already has a locale.
  */
 protected function updateLocale(Route $doc, $id, DocumentManager $dm, $force = false)
 {
     $matches = array();
     // only update if the prefix matches, to allow for more than one
     // listener and more than one route root.
     if (!preg_match('#(' . implode('|', $this->getPrefixes()) . ')/([^/]+)(/|$)#', $id, $matches)) {
         return;
     }
     if (in_array($locale = $matches[2], $this->locales)) {
         if ($force || !$doc->getDefault('_locale')) {
             $doc->setDefault('_locale', $locale);
         }
         if ($force || !$doc->getRequirement('_locale')) {
             $doc->setRequirement('_locale', $locale);
         }
     } else {
         if ($this->addLocalePattern) {
             $doc->setOption('add_locale_pattern', true);
         }
         if ($this->updateAvailableTranslations && $dm->isDocumentTranslatable($doc) && !$doc->getRequirement('_locale')) {
             $locales = $dm->getLocalesFor($doc, true);
             $doc->setRequirement('_locale', implode('|', $locales));
         }
     }
 }
Ejemplo n.º 24
0
 public function testGetRouteChildrenNull()
 {
     $res = $this->route->getRouteChildren();
     $this->assertEquals(array(), $res);
 }
Ejemplo n.º 25
0
 protected function loadVoterMenu(DocumentManager $manager)
 {
     // test content
     $content = new Content();
     $content->setTitle('Content 1');
     $content->setId('/test/content-1');
     $manager->persist($content);
     $route = new Route();
     $route->setId('/test/routes/contents/content-1');
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\MenuBundle\\Tests\\Resources\\Controller\\VoterController::requestContentIdentityAction');
     $route->setContent($content);
     $manager->persist($route);
     // test blog
     $blog = new Content();
     $blog->setTitle('Blog');
     $blog->setId('/test/blog-1');
     $manager->persist($blog);
     $route = new Route();
     $route->setId('/test/routes/blog');
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\MenuBundle\\Tests\\Resources\\Controller\\VoterController::blogAction');
     $route->setContent($blog);
     $manager->persist($route);
     // test blog post
     $post = new Post();
     $post->setTitle('My Post');
     $post->setId('/test/blog-1/my-post');
     $manager->persist($post);
     $route = new Route();
     $route->setId('/test/routes/blog/my-post');
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\MenuBundle\\Tests\\Resources\\Controller\\VoterController::postAction');
     $route->setContent($post);
     $manager->persist($route);
     // test articles
     $articles = new Content();
     $articles->setTitle('Articles Index');
     $articles->setId('/test/articles');
     $manager->persist($articles);
     $articlesRoute = new Route();
     $articlesRoute->setId('/test/routes/articles');
     $articlesRoute->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\MenuBundle\\Tests\\Resources\\Controller\\VoterController::articlesAction');
     $articlesRoute->setContent($articles);
     $articlesRoute->setOption('currentUriPrefix', '/articles');
     $manager->persist($articlesRoute);
     $article1 = new Content();
     $article1->setTitle('Article 1');
     $article1->setId('/test/article-1');
     $manager->persist($article1);
     $route = new Route();
     $route->setId('/test/routes/articles/some-category');
     $manager->persist($route);
     $route = new Route();
     $route->setId('/test/routes/articles/some-category/article-1');
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\MenuBundle\\Tests\\Resources\\Controller\\VoterController::postAction');
     $route->setContent($article1);
     $manager->persist($route);
     // menu items
     $menu = new Menu();
     $menu->setName('side-menu');
     $menu->setLabel('Side Menu');
     $menu->setParentDocument($this->menuRoot);
     $manager->persist($menu);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('Default Behavior');
     $menuNode->setName('default');
     $menuNode->setRoute('current_menu_item_default');
     $manager->persist($menuNode);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('Request Content Identity Voter');
     $menuNode->setName('request-content-identity-voter');
     $menuNode->setContent($content);
     $manager->persist($menuNode);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('URI Prefix Voter');
     $menuNode->setName('uri-prefix-voter');
     $menuNode->setContent($articlesRoute);
     $manager->persist($menuNode);
     $menuNode = new MenuNode();
     $menuNode->setParentDocument($menu);
     $menuNode->setLabel('Request Parent Content Identity Voter');
     $menuNode->setName('request-parent-content-identity-voter');
     $menuNode->setContent($blog);
     $manager->persist($menuNode);
 }
Ejemplo n.º 26
0
 public function setRouteOptions(array $options)
 {
     parent::setOptions($options);
 }
Ejemplo n.º 27
0
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/content');
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes/content');
     $contentRoot = $manager->find(null, '/test/content');
     $routeRoot = $manager->find(null, '/test/routes/content');
     $content = new SeoAwareContent();
     $content->setName('content-1');
     $content->setTitle('Content 1');
     $content->setBody('Content 1');
     $content->setParentDocument($contentRoot);
     $metadata = new SeoMetadata();
     $metadata->setTitle('Title content 1');
     $metadata->setMetaDescription('Description of content 1.');
     $metadata->setMetaKeywords('content1, content');
     $metadata->setOriginalUrl('/to/original');
     $content->setSeoMetadata($metadata);
     $manager->persist($content);
     $route = new Route();
     $route->setPosition($routeRoot, 'content-1');
     $route->setContent($content);
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction');
     $manager->persist($route);
     $content = new ContentWithExtractors();
     $content->setName('strategy-title');
     $content->setTitle('Strategy title');
     $content->setBody('content of strategy test.');
     $content->setParentDocument($contentRoot);
     $manager->persist($content);
     $route = new Route();
     $route->setPosition($routeRoot, 'strategy-content');
     $route->setContent($content);
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction');
     $manager->persist($route);
     $content = new SeoAwareContent();
     $content->setName('content-extra');
     $content->setTitle('Content extra');
     $content->setBody('Content for extra properties.');
     $content->setParentDocument($contentRoot);
     $metadata = new SeoMetadata();
     $metadata->addExtraProperty('og:title', 'extra title');
     $metadata->addExtraName('robots', 'index, follow');
     $metadata->addExtraHttp('Content-Type', 'text/html; charset=utf-8');
     $content->setSeoMetadata($metadata);
     $manager->persist($content);
     $route = new Route();
     $route->setPosition($routeRoot, 'content-extra');
     $route->setContent($content);
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction');
     $manager->persist($route);
     $alternateLocaleContent = new AlternateLocaleContent();
     $alternateLocaleContent->setName('alternate-locale-content');
     $alternateLocaleContent->setTitle('Alternate locale content');
     $alternateLocaleContent->setBody('Body of some alternate locate content');
     $alternateLocaleContent->setParentDocument($contentRoot);
     $manager->persist($alternateLocaleContent);
     $manager->bindTranslation($alternateLocaleContent, 'en');
     // creating the locale base routes as generic for now
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes/de');
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes/en');
     $deRoute = $manager->find(null, '/test/routes/de');
     $enRoute = $manager->find(null, '/test/routes/en');
     $alternateLocaleRoute = new Route();
     $alternateLocaleRoute->setPosition($enRoute, 'alternate-locale-content');
     $alternateLocaleRoute->setContent($alternateLocaleContent);
     $alternateLocaleRoute->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction');
     $manager->persist($alternateLocaleRoute);
     $alternateLocaleContent->setTitle('Alternative Sprachen');
     $manager->bindTranslation($alternateLocaleContent, 'de');
     $alternateLocaleRoute = new Route();
     $alternateLocaleRoute->setPosition($deRoute, 'alternate-locale-content');
     $alternateLocaleRoute->setContent($alternateLocaleContent);
     $alternateLocaleRoute->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction');
     $manager->persist($alternateLocaleRoute);
     // create content in a deeper structure
     $content = new SeoAwareContent();
     $content->setName('content-deeper');
     $content->setTitle('Content deeper');
     $content->setBody('Content deeper Body');
     $content->setParentDocument($contentRoot);
     $manager->persist($content);
     $route = new Route();
     $route->setPosition($manager->find(null, '/test/routes/content/content-1'), 'content-deeper');
     $route->setContent($content);
     $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction');
     $manager->persist($route);
     $manager->flush();
 }
 /**
  * Create a route
  * @param Array $routeInfo The route's information. Name, variable pattern, defaults & requirements
  * @return Route
  */
 private function createRoute($routeInfo)
 {
     $route = new Route();
     $route->setParentDocument($this->documentManager->find(null, $this->config['parameters']['londa.basepath.routes']));
     $route->setName($routeInfo['name']);
     if (isset($routeInfo['variable_pattern'])) {
         $route->setVariablePattern($routeInfo['variable_pattern']);
     }
     if (isset($routeInfo['requirements'])) {
         $this->setRouteRequirements($route, $routeInfo['requirements']);
     }
     if (isset($routeInfo['defaults'])) {
         $this->setRouteDefaults($route, $routeInfo['defaults']);
     }
     return $route;
 }