|
2 | 2 |
|
3 | 3 | namespace Acme\MainBundle\DataFixtures\PHPCR;
|
4 | 4 |
|
5 |
| -use Doctrine\Common\DataFixtures\FixtureInterface; |
6 | 5 | use Doctrine\Common\Persistence\ObjectManager;
|
7 | 6 |
|
8 |
| -use PHPCR\Util\NodeHelper; |
9 |
| - |
10 |
| -use Symfony\Component\DependencyInjection\ContainerInterface; |
11 |
| -use Symfony\Component\DependencyInjection\ContainerAware; |
| 7 | +use Symfony\Component\Yaml\Parser; |
| 8 | +use Symfony\Cmf\Bundle\SimpleCmsBundle\DataFixtures\LoadCmsData; |
12 | 9 |
|
13 | 10 | use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page;
|
14 |
| -use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangPage; |
15 | 11 | use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRoute;
|
16 |
| -use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRedirectRoute; |
17 | 12 | use Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenuItem;
|
18 | 13 |
|
19 |
| -class LoadSimpleCmsData extends ContainerAware implements FixtureInterface |
| 14 | +class LoadSimpleCmsData extends LoadCmsData |
20 | 15 | {
|
21 |
| - public function load(ObjectManager $dm) |
| 16 | + public function getOrder() |
22 | 17 | {
|
23 |
| - $session = $dm->getPhpcrSession(); |
24 |
| - |
25 |
| - $basepath = explode('/', $this->container->getParameter('symfony_cmf_simple_cms.basepath')); |
26 |
| - $rootname = array_pop($basepath); |
27 |
| - $basepath = implode('/', $basepath); |
28 |
| - |
29 |
| - if ($session->nodeExists($basepath)) { |
30 |
| - $session->removeItem($basepath); |
31 |
| - } |
32 |
| - |
33 |
| - NodeHelper::createPath($session, $basepath); |
34 |
| - $base = $dm->find(null, $basepath); |
| 18 | + return 5; |
| 19 | + } |
35 | 20 |
|
36 |
| - $root = $this->createPage($dm, $base, $rootname, 'Homepage', array('en' => array('Welcome to the CMF Standard Edition', 'This is should get you started with the Symfony CMF.'), 'de' => array('Willkommen zur CMF Standard Edition', 'Dies sollte Ihnen einen Einstieg in das Symfony CMF bieten.'))); |
37 |
| - $this->createPage($dm, $root, 'about', 'About us', array('' => array('Some information about us', 'The about us page with some content'))); |
38 |
| - $contact = $this->createPage($dm, $root, 'contact', 'Contact', array('' => array('A contact page', 'Please send an email to [email protected]'))); |
39 |
| - $this->createPage($dm, $contact, 'map', 'Map', array('en' => array('A map of a location in the US', 'Have a look at the map to find us.'), 'de' => array('Eine Karte von einem Ort in Deutschland', 'Hier können Sie uns finden.'))); |
40 |
| - $this->createPage($dm, $contact, 'team', 'Team', array('' => array('A team page', 'Our team consists of C, M and F.'))); |
| 21 | + protected function getData() |
| 22 | + { |
| 23 | + $yaml = new Parser(); |
| 24 | + return $yaml->parse(file_get_contents(__DIR__.'/../../Resources/data/page.yml')); |
| 25 | + } |
41 | 26 |
|
42 |
| - $this->createMenuItem($dm, $root, 'link', 'http://cmf.symfony.com', array('en' => 'Website', 'de' => 'Webseite')); |
| 27 | + public function load(ObjectManager $dm) |
| 28 | + { |
| 29 | + parent::load($dm); |
43 | 30 |
|
44 |
| - $route = new MultilangRedirectRoute(); |
45 |
| - $route->setPosition($root, 'demo'); |
46 |
| - $route->setUri('http://cmf.liip.ch'); |
47 |
| - $dm->persist($route); |
| 31 | + $yaml = new Parser(); |
| 32 | + $data = $yaml->parse(file_get_contents(__DIR__ . '/../../Resources/data/external.yml')); |
48 | 33 |
|
49 |
| - $this->createMenuItem($dm, $root, 'demo_redirect', $route, array('en' => 'Demo', 'de' => 'Demo')); |
| 34 | + $basepath = $this->container->getParameter('symfony_cmf_simple_cms.basepath'); |
| 35 | + $home = $dm->find(null, $basepath); |
50 | 36 |
|
51 | 37 | $route = new MultilangRoute();
|
52 |
| - $route->setPosition($root, 'dynamic'); |
| 38 | + $route->setPosition($home, 'dynamic'); |
53 | 39 | $route->setDefault('_controller', 'AcmeMainBundle:Demo:dynamic');
|
54 | 40 |
|
55 | 41 | $dm->persist($route);
|
56 | 42 |
|
57 |
| - $this->createMenuItem($dm, $root, 'hardcoded_dynamic', $route, array('en' => 'Dynamic', 'de' => 'Dynamisch')); |
58 |
| - |
59 |
| - $this->createMenuItem($dm, $root, 'hardcoded_static', 'static', array('en' => 'Static', 'de' => 'Statisch')); |
60 |
| - |
61 |
| - $dm->flush(); |
62 |
| - } |
63 |
| - |
64 |
| - /** |
65 |
| - * @return Page instance with the specified information |
66 |
| - */ |
67 |
| - protected function createPage(ObjectManager $dm, $parent, $name, $label, array $content) |
68 |
| - { |
69 |
| - $page = new MultilangPage(); |
70 |
| - $page->setPosition($parent, $name); |
71 |
| - $page->setLabel($label); |
72 |
| - |
73 |
| - $dm->persist($page); |
74 |
| - foreach ($content as $locale => $data) { |
75 |
| - $page->setTitle($data[0]); |
76 |
| - $page->setBody($data[1]); |
77 |
| - if ($locale) { |
78 |
| - $dm->bindTranslation($page, $locale); |
| 43 | + foreach ($data['static'] as $name => $overview) { |
| 44 | + $menuItem = new MultilangMenuItem(); |
| 45 | + $menuItem->setName($name); |
| 46 | + $menuItem->setParent($home); |
| 47 | + if (!empty($overview['uri'])) |
| 48 | + $menuItem->setUri($overview['uri']); |
| 49 | + else |
| 50 | + { |
| 51 | + $menuItem->setRoute($dm->find(null, $basepath.'/'.$overview['route'])->getId()); |
79 | 52 | }
|
80 |
| - } |
81 |
| - |
82 |
| - return $page; |
83 |
| - } |
84 |
| - |
85 |
| - /** |
86 |
| - * @return MenuItem instance with the specified information |
87 |
| - */ |
88 |
| - protected function createMenuItem(ObjectManager $dm, $parent, $name, $target, array $content) |
89 |
| - { |
90 |
| - $menuItem = new MultilangMenuItem(); |
91 |
| - $menuItem->setPosition($parent, $name); |
92 |
| - if (is_object($target)) { |
93 |
| - $menuItem->setRoute($target->getId()); |
94 |
| - } else { |
95 |
| - $menuItem->setUri($target); |
96 |
| - } |
97 |
| - |
98 |
| - $dm->persist($menuItem); |
99 |
| - foreach ($content as $locale => $label) { |
100 |
| - $menuItem->setLabel($label); |
101 |
| - if ($locale) { |
102 |
| - $dm->bindTranslation($menuItem, $locale); |
| 53 | + |
| 54 | + $dm->persist($menuItem); |
| 55 | + foreach ($overview['label'] as $locale => $label) { |
| 56 | + $menuItem->setLabel($label); |
| 57 | + if ($locale) { |
| 58 | + $dm->bindTranslation($menuItem, $locale); |
| 59 | + } |
103 | 60 | }
|
104 | 61 | }
|
105 | 62 |
|
106 |
| - return $menuItem; |
| 63 | + $dm->flush(); |
107 | 64 | }
|
108 | 65 | }
|
0 commit comments