|
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; |
| 7 | +use Symfony\Component\Yaml\Parser; |
9 | 8 |
|
10 |
| -use Symfony\Component\DependencyInjection\ContainerInterface; |
11 |
| -use Symfony\Component\DependencyInjection\ContainerAware; |
12 |
| - |
13 |
| -use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page; |
14 |
| -use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangPage; |
15 |
| -use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRoute; |
| 9 | +use Symfony\Cmf\Bundle\SimpleCmsBundle\DataFixtures\LoadCmsData; |
16 | 10 | use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRedirectRoute;
|
| 11 | +use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRoute; |
| 12 | + |
17 | 13 | use Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenuItem;
|
18 | 14 |
|
19 |
| -class LoadSimpleCmsData extends ContainerAware implements FixtureInterface |
| 15 | +class LoadSimpleCmsData extends LoadCmsData |
20 | 16 | {
|
21 |
| - public function load(ObjectManager $dm) |
22 |
| - { |
23 |
| - $session = $dm->getPhpcrSession(); |
| 17 | + private $yaml; |
24 | 18 |
|
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 |
| - } |
| 19 | + public function getOrder() |
| 20 | + { |
| 21 | + return 5; |
| 22 | + } |
32 | 23 |
|
33 |
| - NodeHelper::createPath($session, $basepath); |
34 |
| - $base = $dm->find(null, $basepath); |
| 24 | + protected function getData() |
| 25 | + { |
| 26 | + return $this->yaml->parse(file_get_contents(__DIR__.'/../../Resources/data/page.yml')); |
| 27 | + } |
35 | 28 |
|
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.'))); |
| 29 | + public function load(ObjectManager $dm) |
| 30 | + { |
| 31 | + $this->yaml = new Parser(); |
41 | 32 |
|
42 |
| - $this->createMenuItem($dm, $root, 'link', 'http://cmf.symfony.com', array('en' => 'Website', 'de' => 'Webseite')); |
| 33 | + parent::load($dm); |
43 | 34 |
|
44 |
| - $route = new MultilangRedirectRoute(); |
45 |
| - $route->setPosition($root, 'demo'); |
46 |
| - $route->setUri('http://cmf.liip.ch'); |
47 |
| - $dm->persist($route); |
| 35 | + $data = $this->yaml->parse(file_get_contents(__DIR__ . '/../../Resources/data/external.yml')); |
48 | 36 |
|
49 |
| - $this->createMenuItem($dm, $root, 'demo_redirect', $route, array('en' => 'Demo', 'de' => 'Demo')); |
| 37 | + $basepath = $this->container->getParameter('symfony_cmf_simple_cms.basepath'); |
| 38 | + $home = $dm->find(null, $basepath); |
50 | 39 |
|
51 | 40 | $route = new MultilangRoute();
|
52 |
| - $route->setPosition($root, 'dynamic'); |
| 41 | + $route->setPosition($home, 'dynamic'); |
53 | 42 | $route->setDefault('_controller', 'AcmeMainBundle:Demo:dynamic');
|
54 | 43 |
|
55 | 44 | $dm->persist($route);
|
56 | 45 |
|
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); |
| 46 | + foreach ($data['static'] as $name => $overview) { |
| 47 | + $menuItem = new MultilangMenuItem(); |
| 48 | + $menuItem->setName($name); |
| 49 | + $menuItem->setParent($home); |
| 50 | + if (!empty($overview['route'])) { |
| 51 | + if (!empty($overview['uri'])) { |
| 52 | + $route = new MultilangRedirectRoute(); |
| 53 | + $route->setPosition($home, $overview['route']); |
| 54 | + $route->setUri($overview['uri']); |
| 55 | + $dm->persist($route); |
| 56 | + } else { |
| 57 | + $route = $dm->find(null, $basepath.'/'.$overview['route']); |
| 58 | + } |
| 59 | + $menuItem->setRoute($route->getId()); |
| 60 | + } else { |
| 61 | + $menuItem->setUri($overview['uri']); |
79 | 62 | }
|
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); |
| 63 | + |
| 64 | + $dm->persist($menuItem); |
| 65 | + foreach ($overview['label'] as $locale => $label) { |
| 66 | + $menuItem->setLabel($label); |
| 67 | + if ($locale) { |
| 68 | + $dm->bindTranslation($menuItem, $locale); |
| 69 | + } |
103 | 70 | }
|
104 | 71 | }
|
105 | 72 |
|
106 |
| - return $menuItem; |
| 73 | + $dm->flush(); |
107 | 74 | }
|
108 | 75 | }
|
0 commit comments