1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher Fixtures Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2015 Sourcefabric z.ú. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2015 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\FixturesBundle\DataFixtures\ORM; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\DataFixtures\FixtureInterface; |
18
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
19
|
|
|
use SWP\Bundle\CoreBundle\Model\MenuItem; |
20
|
|
|
use SWP\Bundle\FixturesBundle\AbstractFixture; |
21
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
22
|
|
|
|
23
|
|
|
class LoadMenuNodesData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function load(ObjectManager $manager) |
29
|
|
|
{ |
30
|
|
|
$env = $this->getEnvironment(); |
31
|
|
|
$menuNodes = [ |
32
|
|
|
'dev' => [ |
33
|
|
|
[ |
34
|
|
|
'name' => 'home', |
35
|
|
|
'label' => 'Home', |
36
|
|
|
'locale' => 'en', |
37
|
|
|
'parent' => 'mainNavigation', |
38
|
|
|
'uri' => '/', |
39
|
|
|
], |
40
|
|
|
[ |
41
|
|
|
'name' => 'politics', |
42
|
|
|
'label' => 'Politics', |
43
|
|
|
'locale' => 'en', |
44
|
|
|
'parent' => 'mainNavigation', |
45
|
|
|
'route' => 'politics', |
46
|
|
|
], |
47
|
|
|
[ |
48
|
|
|
'name' => 'business', |
49
|
|
|
'label' => 'Business', |
50
|
|
|
'locale' => 'en', |
51
|
|
|
'parent' => 'mainNavigation', |
52
|
|
|
'route' => 'business', |
53
|
|
|
], |
54
|
|
|
[ |
55
|
|
|
'name' => 'scitech', |
56
|
|
|
'label' => 'Sci/Tech', |
57
|
|
|
'locale' => 'en', |
58
|
|
|
'parent' => 'mainNavigation', |
59
|
|
|
'route' => 'scitech', |
60
|
|
|
], |
61
|
|
|
[ |
62
|
|
|
'name' => 'health', |
63
|
|
|
'label' => 'Health', |
64
|
|
|
'locale' => 'en', |
65
|
|
|
'parent' => 'mainNavigation', |
66
|
|
|
'route' => 'health', |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
'name' => 'entertainment', |
70
|
|
|
'label' => 'Entertainment', |
71
|
|
|
'locale' => 'en', |
72
|
|
|
'parent' => 'mainNavigation', |
73
|
|
|
'route' => 'entertainment', |
74
|
|
|
], |
75
|
|
|
[ |
76
|
|
|
'name' => 'sports', |
77
|
|
|
'label' => 'Sports', |
78
|
|
|
'locale' => 'en', |
79
|
|
|
'parent' => 'mainNavigation', |
80
|
|
|
'route' => 'sports', |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
'name' => 'politics', |
84
|
|
|
'label' => 'Politics', |
85
|
|
|
'locale' => 'en', |
86
|
|
|
'parent' => 'footerPrim', |
87
|
|
|
'route' => 'politics', |
88
|
|
|
], |
89
|
|
|
[ |
90
|
|
|
'name' => 'business', |
91
|
|
|
'label' => 'Business', |
92
|
|
|
'locale' => 'en', |
93
|
|
|
'parent' => 'footerPrim', |
94
|
|
|
'route' => 'business', |
95
|
|
|
], |
96
|
|
|
[ |
97
|
|
|
'name' => 'scitech', |
98
|
|
|
'label' => 'Sci/Tech', |
99
|
|
|
'locale' => 'en', |
100
|
|
|
'parent' => 'footerPrim', |
101
|
|
|
'route' => 'scitech', |
102
|
|
|
], |
103
|
|
|
[ |
104
|
|
|
'name' => 'health', |
105
|
|
|
'label' => 'Health', |
106
|
|
|
'locale' => 'en', |
107
|
|
|
'parent' => 'footerPrim', |
108
|
|
|
'route' => 'health', |
109
|
|
|
], |
110
|
|
|
[ |
111
|
|
|
'name' => 'entertainment', |
112
|
|
|
'label' => 'Entertainment', |
113
|
|
|
'locale' => 'en', |
114
|
|
|
'parent' => 'footerPrim', |
115
|
|
|
'route' => 'entertainment', |
116
|
|
|
], |
117
|
|
|
[ |
118
|
|
|
'name' => 'sports', |
119
|
|
|
'label' => 'Sports', |
120
|
|
|
'locale' => 'en', |
121
|
|
|
'parent' => 'footerPrim', |
122
|
|
|
'route' => 'sports', |
123
|
|
|
], |
124
|
|
|
], |
125
|
|
|
'test' => [ |
126
|
|
|
[ |
127
|
|
|
'name' => 'home', |
128
|
|
|
'label' => 'Home', |
129
|
|
|
'locale' => 'en', |
130
|
|
|
'uri' => 'http://example.com/home', |
131
|
|
|
'parent' => 'test', |
132
|
|
|
], |
133
|
|
|
[ |
134
|
|
|
'name' => 'contact', |
135
|
|
|
'label' => 'Contact', |
136
|
|
|
'locale' => 'en', |
137
|
|
|
'uri' => 'http://example.com/contact', |
138
|
|
|
'parent' => 'test', |
139
|
|
|
], |
140
|
|
|
[ |
141
|
|
|
'name' => 'sub', |
142
|
|
|
'label' => 'Sub Contact', |
143
|
|
|
'locale' => 'en', |
144
|
|
|
'uri' => 'http://example.com/contact/sub', |
145
|
|
|
'parent' => 'contact', |
146
|
|
|
], |
147
|
|
|
], |
148
|
|
|
]; |
149
|
|
|
|
150
|
|
|
if (isset($menuNodes[$env])) { |
151
|
|
|
$factory = $this->container->get('swp.factory.menu'); |
152
|
|
|
$repository = $this->container->get('swp.repository.menu'); |
153
|
|
|
$routeRepository = $this->container->get('swp.repository.route'); |
154
|
|
|
foreach ($menuNodes[$env] as $menuNodeData) { |
155
|
|
|
/** @var MenuItem $menuNode */ |
156
|
|
|
$menuNode = $factory->createItem($menuNodeData['name']); |
157
|
|
|
if (isset($menuNodeData['route'])) { |
158
|
|
|
$route = $routeRepository->findOneBy(['name' => $menuNodeData['route']]); |
159
|
|
|
/** @var MenuItem $menuNode */ |
160
|
|
|
$menuNode = $factory->createItem($menuNodeData['name'], ['route' => $route ? $route->getName() : null]); |
161
|
|
|
$menuNode->setRoute($route); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$menuNode->setLabel($menuNodeData['label']); |
165
|
|
|
if (isset($menuNodeData['uri'])) { |
166
|
|
|
$menuNode->setUri($menuNodeData['uri']); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
if (isset($menuNodeData['parent'])) { |
170
|
|
|
$menuNode->setParent($repository->getOneMenuItemByName($menuNodeData['parent'])); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$manager->persist($menuNode); |
174
|
|
|
$manager->flush(); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function getOrder() |
180
|
|
|
{ |
181
|
|
|
return 5; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|