5
5
use Doctrine \Common \Persistence \ObjectManager ;
6
6
7
7
use Symfony \Component \Yaml \Parser ;
8
- use Symfony \Cmf \Bundle \SimpleCmsBundle \DataFixtures \LoadCmsData ;
9
8
10
- use Symfony \Cmf \Bundle \SimpleCmsBundle \Document \Page ;
9
+ use Symfony \Cmf \Bundle \SimpleCmsBundle \DataFixtures \LoadCmsData ;
10
+ use Symfony \Cmf \Bundle \SimpleCmsBundle \Document \MultilangRedirectRoute ;
11
11
use Symfony \Cmf \Bundle \SimpleCmsBundle \Document \MultilangRoute ;
12
+
12
13
use Symfony \Cmf \Bundle \MenuBundle \Document \MultilangMenuItem ;
13
14
14
15
class LoadSimpleCmsData extends LoadCmsData
15
16
{
17
+ private $ yaml ;
18
+
16
19
public function getOrder ()
17
20
{
18
21
return 5 ;
19
22
}
20
23
21
24
protected function getData ()
22
25
{
23
- $ yaml = new Parser ();
24
- return $ yaml ->parse (file_get_contents (__DIR__ .'/../../Resources/data/page.yml ' ));
26
+ return $ this ->yaml ->parse (file_get_contents (__DIR__ .'/../../Resources/data/page.yml ' ));
25
27
}
26
28
27
29
public function load (ObjectManager $ dm )
28
30
{
31
+ $ this ->yaml = new Parser ();
32
+
29
33
parent ::load ($ dm );
30
34
31
- $ yaml = new Parser ();
32
- $ data = $ yaml ->parse (file_get_contents (__DIR__ . '/../../Resources/data/external.yml ' ));
35
+ $ data = $ this ->yaml ->parse (file_get_contents (__DIR__ . '/../../Resources/data/external.yml ' ));
33
36
34
37
$ basepath = $ this ->container ->getParameter ('symfony_cmf_simple_cms.basepath ' );
35
38
$ home = $ dm ->find (null , $ basepath );
@@ -44,11 +47,18 @@ public function load(ObjectManager $dm)
44
47
$ menuItem = new MultilangMenuItem ();
45
48
$ menuItem ->setName ($ name );
46
49
$ menuItem ->setParent ($ home );
47
- if (!empty ($ overview ['uri ' ]))
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 {
48
61
$ menuItem ->setUri ($ overview ['uri ' ]);
49
- else
50
- {
51
- $ menuItem ->setRoute ($ dm ->find (null , $ basepath .'/ ' .$ overview ['route ' ])->getId ());
52
62
}
53
63
54
64
$ dm ->persist ($ menuItem );
0 commit comments