|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace C33s\StaticPageContentBundle\Menu; |
|
4
|
|
|
|
|
5
|
|
|
use C33s\MenuBundle\Exception\OptionRequiredException; |
|
6
|
|
|
use C33s\MenuBundle\Item\MenuItem; |
|
7
|
|
|
use C33s\MenuBundle\Menu\Menu; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Description of SimpleContentMenuItem |
|
11
|
|
|
* |
|
12
|
|
|
* @author david |
|
13
|
|
|
*/ |
|
14
|
|
|
class StaticPageContentMenuItem extends MenuItem |
|
15
|
|
|
{ |
|
16
|
|
|
protected $staticPageName; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Construct a new menu item. It requires its routeName, options and |
|
20
|
|
|
* the menu the item is assigned to. |
|
21
|
|
|
* |
|
22
|
|
|
* SimpleContentMenuItem requires the following routeName notation: |
|
23
|
|
|
* routeName/pageName |
|
24
|
|
|
* |
|
25
|
|
|
* @see MenuItem::__construct() |
|
26
|
|
|
* |
|
27
|
|
|
* @throws OptionRequiredException |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $routeName |
|
30
|
|
|
* @param array $options |
|
31
|
|
|
* @param Menu $menu |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($routeName, array $options, Menu $menu) |
|
34
|
|
|
{ |
|
35
|
|
|
if (false === strpos($routeName, '/')) { |
|
36
|
|
|
if (isset($options['set_request_variables']['name'])) { |
|
37
|
|
|
$this->staticPageName = $options['set_request_variables']['name']; |
|
38
|
|
|
} else { |
|
39
|
|
|
throw new OptionRequiredException('StaticPageContentMenuItem requires either routeName/pageName notation or a "name" variable in "set_request_variables"'); |
|
40
|
|
|
} |
|
41
|
|
|
} else { |
|
42
|
|
|
list($routeName, $this->staticPageName) = explode('/', $routeName, 2); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$options['match_request_variables']['name'] = $this->staticPageName; |
|
46
|
|
|
|
|
47
|
|
|
parent::__construct($routeName, $options, $menu); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Add variable values defined in $addRequestVariables to the given |
|
52
|
|
|
* urlParameters. This can be used to pass through generally available |
|
53
|
|
|
* request parameters. |
|
54
|
|
|
* |
|
55
|
|
|
* @param array $urlParameters |
|
56
|
|
|
* |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function addRequestVariablesToUrlParameters(array $urlParameters) |
|
60
|
|
|
{ |
|
61
|
|
|
$urlParameters = parent::addRequestVariablesToUrlParameters($urlParameters); |
|
62
|
|
|
$urlParameters['name'] = $this->staticPageName; |
|
63
|
|
|
|
|
64
|
|
|
return $urlParameters; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Add a child to the menu using item data. |
|
69
|
|
|
* |
|
70
|
|
|
* Possible value for position are: |
|
71
|
|
|
* * 'last': insert at last position (append), this is the default |
|
72
|
|
|
* * 'first': insert at first position |
|
73
|
|
|
* * positive number (e.g. 2): insert at this position, count starts at 0 |
|
74
|
|
|
* * negative number (e.g. -1): insert at this position from the END of the children backwards |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $routeName |
|
77
|
|
|
* @param array $options |
|
78
|
|
|
* @param string $position |
|
79
|
|
|
* |
|
80
|
|
|
* @return MenuItem The generated item |
|
81
|
|
|
*/ |
|
82
|
|
|
public function addChildByData($routeName, $options, $position = 'last') |
|
83
|
|
|
{ |
|
84
|
|
|
if (substr($routeName, 0, 2) == './') { |
|
85
|
|
|
$routeName = $this->routeName.'/'.$this->staticPageName.substr($routeName, 1); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return parent::addChildByData($routeName, $options, $position); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|