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\FixturesBundle\AbstractFixture; |
20
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
21
|
|
|
|
22
|
|
|
class LoadMenuNodesData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
4 |
|
public function load(ObjectManager $manager) |
28
|
|
|
{ |
29
|
4 |
|
$env = $this->getEnvironment(); |
30
|
|
|
$menuNodes = [ |
31
|
|
|
'dev' => [ |
32
|
|
|
[ |
33
|
|
|
'name' => 'home', |
34
|
|
|
'label' => 'Home', |
35
|
|
|
'locale' => 'en', |
36
|
|
|
], |
37
|
4 |
|
], |
38
|
|
|
'test' => [ |
39
|
|
|
[ |
40
|
|
|
'name' => 'home', |
41
|
|
|
'label' => 'Home', |
42
|
|
|
'locale' => 'en', |
43
|
|
|
'uri' => 'http://example.com/home', |
44
|
|
|
'parent' => 1, |
45
|
|
|
], |
46
|
|
|
[ |
47
|
|
|
'name' => 'contact', |
48
|
|
|
'label' => 'Contact', |
49
|
|
|
'locale' => 'en', |
50
|
|
|
'uri' => 'http://example.com/contact', |
51
|
|
|
'parent' => 1, |
52
|
|
|
], |
53
|
|
|
[ |
54
|
|
|
'name' => 'sub', |
55
|
|
|
'label' => 'Sub Contact', |
56
|
|
|
'locale' => 'en', |
57
|
|
|
'uri' => 'http://example.com/contact/sub', |
58
|
|
|
'parent' => 3, |
59
|
|
|
], |
60
|
|
|
], |
61
|
|
|
]; |
62
|
|
|
|
63
|
4 |
|
if (isset($menuNodes[$env])) { |
64
|
4 |
|
$factory = $this->container->get('swp.factory.menu'); |
65
|
4 |
|
$repository = $this->container->get('swp.repository.menu'); |
66
|
4 |
|
foreach ($menuNodes[$env] as $menuNodeData) { |
67
|
4 |
|
$menuNode = $factory->createItem($menuNodeData['name']); |
68
|
4 |
|
$menuNode->setLabel($menuNodeData['label']); |
69
|
4 |
|
if (isset($menuNodeData['uri'])) { |
70
|
4 |
|
$menuNode->setUri($menuNodeData['uri']); |
71
|
|
|
} |
72
|
4 |
|
if (isset($menuNodeData['route'])) { |
73
|
|
|
$menuNode->setRoute($menuNodeData['route']); |
74
|
|
|
} |
75
|
4 |
|
if (isset($menuNodeData['parent'])) { |
76
|
4 |
|
$menuNode->setParent($repository->getOneMenuItemById($menuNodeData['parent'])); |
77
|
|
|
} |
78
|
|
|
|
79
|
4 |
|
$manager->persist($menuNode); |
80
|
4 |
|
$manager->flush(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
4 |
|
} |
84
|
|
|
|
85
|
4 |
|
public function getOrder() |
86
|
|
|
{ |
87
|
4 |
|
return 5; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|