/**
  * Load data fixtures with the passed DocumentManager
  *
  * @param DocumentManager $manager
  */
 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.");
     }
     // tweak homepage
     $page = $manager->find(null, '/cms/simple');
     $page->setBody('Hello');
     $page->setDefault('_template', 'AcmeDemoBundle::home.html.twig');
     // add menu item for home
     $menuRoot = $manager->find(null, '/cms/simple');
     $homeMenuNode = new MenuNode('home');
     $homeMenuNode->setLabel('Home');
     $homeMenuNode->setParentDocument($menuRoot);
     $homeMenuNode->setContent($page);
     $manager->persist($homeMenuNode);
     // load the pages
     Fixtures::load(array(__DIR__ . '/../../Resources/data/pages.yml'), $manager);
     // add menu item for login
     $loginMenuNode = new MenuNode('login');
     $loginMenuNode->setLabel('Admin Login');
     $loginMenuNode->setParentDocument($menuRoot);
     $loginMenuNode->setRoute('_demo_login');
     $manager->persist($loginMenuNode);
     // load the blocks
     NodeHelper::createPath($manager->getPhpcrSession(), '/cms/content/blocks');
     Fixtures::load(array(__DIR__ . '/../../Resources/data/blocks.yml'), $manager);
     // save the changes
     $manager->flush();
 }
 public function load(ObjectManager $dm)
 {
     $this->yaml = new Parser();
     parent::load($dm);
     $data = $this->yaml->parse(file_get_contents(__DIR__ . '/../../Resources/data/external.yml'));
     $basepath = $this->getBasePath();
     $home = $dm->find(null, $basepath);
     $route = new MultilangRoute();
     $route->setPosition($home, 'dynamic');
     $route->setDefault('_controller', 'AcmeMainBundle:Demo:dynamic');
     $dm->persist($route);
     foreach ($data['static'] as $name => $overview) {
         $menuItem = new MenuNode();
         $menuItem->setName($name);
         $menuItem->setParent($home);
         if (!empty($overview['route'])) {
             if (!empty($overview['uri'])) {
                 $route = new MultilangRedirectRoute();
                 $route->setPosition($home, $overview['route']);
                 $route->setUri($overview['uri']);
                 $dm->persist($route);
             } else {
                 $route = $dm->find(null, $basepath . '/' . $overview['route']);
             }
             $menuItem->setRoute($route->getId());
         } else {
             $menuItem->setUri($overview['uri']);
         }
         $dm->persist($menuItem);
         foreach ($overview['label'] as $locale => $label) {
             $menuItem->setLabel($label);
             if ($locale) {
                 $dm->bindTranslation($menuItem, $locale);
             }
         }
     }
     $dm->flush();
 }
Example #3
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);
 }
Example #4
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);
 }