Skip to content

Commit 73083a4

Browse files
committed
Refactored fixture data to use SimpleCMS fixture loading mechanism
1 parent 612f47d commit 73083a4

File tree

3 files changed

+98
-79
lines changed

3 files changed

+98
-79
lines changed

src/Acme/MainBundle/DataFixtures/PHPCR/LoadSimpleCmsData.php

Lines changed: 36 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,64 @@
22

33
namespace Acme\MainBundle\DataFixtures\PHPCR;
44

5-
use Doctrine\Common\DataFixtures\FixtureInterface;
65
use Doctrine\Common\Persistence\ObjectManager;
76

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;
129

1310
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page;
14-
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangPage;
1511
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRoute;
16-
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRedirectRoute;
1712
use Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenuItem;
1813

19-
class LoadSimpleCmsData extends ContainerAware implements FixtureInterface
14+
class LoadSimpleCmsData extends LoadCmsData
2015
{
21-
public function load(ObjectManager $dm)
16+
public function getOrder()
2217
{
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+
}
3520

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+
}
4126

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);
4330

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'));
4833

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);
5036

5137
$route = new MultilangRoute();
52-
$route->setPosition($root, 'dynamic');
38+
$route->setPosition($home, 'dynamic');
5339
$route->setDefault('_controller', 'AcmeMainBundle:Demo:dynamic');
5440

5541
$dm->persist($route);
5642

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());
7952
}
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+
}
10360
}
10461
}
10562

106-
return $menuItem;
63+
$dm->flush();
10764
}
10865
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
static:
2+
docs:
3+
label:
4+
en: "Website"
5+
de: "Website"
6+
uri: "http://cmf.symfony.com/"
7+
demo:
8+
label:
9+
en: "Demo"
10+
de: "Demo"
11+
uri: "http://cmf.liip.ch/"
12+
hardcoded_dynamic:
13+
label:
14+
en: "Dynamic"
15+
de: "Dynamisch"
16+
route: "dynamic"
17+
hardcoded_static:
18+
label:
19+
en: "Static"
20+
de: "Statisch"
21+
uri: "static"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
static:
2+
home:
3+
name: ""
4+
title:
5+
en: "Welcome to the CMF Standard Edition"
6+
de: "Willkommen zur CMF Standard Edition"
7+
body:
8+
en: "This is should get you started with the Symfony CMF."
9+
de: "Dies sollte Ihnen einen Einstieg in das Symfony CMF bieten."
10+
11+
about:
12+
name: "about"
13+
label: "About us"
14+
title: "Some information about us"
15+
content: "The about us page with some content"
16+
17+
contact:
18+
name: "contact"
19+
label: "Contact"
20+
title: "A contact page"
21+
content: "Please send an email to [email protected]"
22+
23+
map:
24+
name: "map"
25+
label:
26+
en: "Map"
27+
de: "Karte"
28+
parent: "/contact"
29+
title:
30+
en: "A map of a location in the US"
31+
de: "Eine Karte von einem Ort in Deutschland"
32+
body:
33+
en: "Have a look at the map to find us."
34+
de: "Hier können Sie uns finden."
35+
36+
team:
37+
name: "team"
38+
label: "Team"
39+
parent: "/contact"
40+
title: "A team page"
41+
content: "Our team consists of C, M and F."

0 commit comments

Comments
 (0)