Skip to content
This repository was archived by the owner on Feb 22, 2019. It is now read-only.

Commit da6e32b

Browse files
committed
feat #2 add more configuration options for navigation (sstok)
This PR was merged into the master branch. Discussion ---------- |Q |A | |--- |---| |Bug Fix |yes| |New Feature |yes| |Deprecations |no | |Fixed Tickets| | |License |MIT| Sent using [Gush](https://github.com/gushphp/gush) Commits ------- 92424e2 add more configuration options for navigation - options (passed directly to the MenuItem) - uri (as alternative to route) (sstok)
2 parents afa4d65 + 92424e2 commit da6e32b

File tree

5 files changed

+105
-31
lines changed

5 files changed

+105
-31
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ rollerworks_navigation:
7878
label: ~ # Label of the breadcrumb will be translated with the translator_domain
7979
translator_domain: Menus # translator domain for the label
8080
route: { name: ~, parameters: { } } # name can not be empty
81+
uri: ~ # Alternatively you can use a URI instead of a route
8182
items: [] # Sub-level items, same as this example (unlimited depth nesting)
8283

8384
# alternatively you can reference a service for getting the Menu object
@@ -124,6 +125,7 @@ rollerworks_navigation:
124125
label: ~ # Label of the breadcrumb will be translated with the translator_domain
125126
translator_domain: Breadcrumbs # translator domain for the label
126127
route: { name: ~, parameters: { } } # name can not be empty
128+
uri: ~ # Alternatively you can use a URI instead of a route
127129
128130
# alternatively you can reference a service for getting the Menu object
129131
# The service must return a Knp\Menu\ItemInterface instance

src/Rollerworks/Bundle/NavigationBundle/DependencyInjection/Configuration.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ public function getConfigTreeBuilder()
6060
->children()
6161
->scalarNode('parent')->defaultNull()->end()
6262
->scalarNode('label')->defaultNull()->end()
63+
->arrayNode('options')
64+
->useAttributeAsKey('name')
65+
->prototype('variable')->end()
66+
->end()
6367
->scalarNode('translator_domain')->defaultValue('Breadcrumbs')->end()
68+
->scalarNode('uri')->defaultNull()->end()
6469
->arrayNode('route')
6570
->children()
6671
->scalarNode('name')->cannotBeEmpty()->end()
72+
->booleanNode('absolute')->defaultFalse()->end()
6773
->arrayNode('parameters')
6874
->prototype('variable')->end()
6975
->end()
@@ -94,17 +100,22 @@ final public function addItemConfig(ArrayNodeDefinition $rootNode)
94100
->children()
95101
->scalarNode('expression')->defaultNull()->end()
96102
->scalarNode('label')->defaultNull()->end()
103+
->arrayNode('options')
104+
->useAttributeAsKey('name')
105+
->prototype('variable')->end()
106+
->end()
97107
->scalarNode('translator_domain')->defaultValue('Menus')->end()
108+
->scalarNode('uri')->defaultNull()->end()
98109
->arrayNode('route')
99110
->children()
100111
->scalarNode('name')->cannotBeEmpty()->end()
112+
->booleanNode('absolute')->defaultFalse()->end()
101113
->arrayNode('parameters')
102114
->useAttributeAsKey('name')
103115
->prototype('variable')->end()
104116
->end()
105117
->end()
106118
->end()
107-
108119
->arrayNode('service')
109120
->children()
110121
->scalarNode('id')->cannotBeEmpty()->end()
@@ -114,7 +125,6 @@ final public function addItemConfig(ArrayNodeDefinition $rootNode)
114125
->end()
115126
->end()
116127
->end()
117-
118128
->arrayNode('items')
119129
->useAttributeAsKey('name')
120130
->prototype('variable')->end() // use variable as we can't nest to deep
@@ -124,6 +134,10 @@ final public function addItemConfig(ArrayNodeDefinition $rootNode)
124134
->ifTrue(function ($v) { return !empty($v['service']) && (!empty($v['expression']) || null !== $v['label']); })
125135
->thenInvalid('When a "service" or "expression" is set no other configurations should be set for this item.')
126136
->end()
137+
->validate()
138+
->ifTrue(function ($v) { return !empty($v['route']) && !empty($v['uri']); })
139+
->thenInvalid('An item can only have a route or uri, not both.')
140+
->end()
127141
->validate()
128142
->ifTrue(function ($v) { return empty($v['service']) && empty($v['expression']) && null === $v['label']; })
129143
->thenInvalid('Missing a value for either "service" or "label" for this item.')

src/Rollerworks/Bundle/NavigationBundle/DependencyInjection/NavigationExtension.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function registerBreadcrumbs(array $breadcrumbs, ContainerBuilder $conta
131131
*
132132
* @return Definition
133133
*/
134-
private function createMenuItem($name, array $options = array())
134+
private function createMenuItem($name, $options = array())
135135
{
136136
unset($options['items']);
137137

@@ -152,9 +152,16 @@ private function createMenuItem($name, array $options = array())
152152
private function createMenuItemDefinition($name, array $item)
153153
{
154154
if (isset($item['route']['parameters'])) {
155-
$item['route']['parameters'] = $this->resolveParameters($item['route']['parameters']);
155+
$item['routeParameters'] = $this->resolveParameters($item['route']['parameters']);
156+
$item['routeAbsolute'] = $this->resolveParameters($item['route']['absolute']);
157+
$item['route'] = $this->resolveParameters($item['route']['name']);
156158
}
157159

160+
$item['options'] = $this->resolveParameters($item['options']);
161+
$item = array_merge($item['options'], $item);
162+
163+
unset($item['options']);
164+
158165
if (!empty($item['service'])) {
159166
$definition = new Definition('stdClass');
160167
$definition->setFactoryService($item['service']['id']);
@@ -234,7 +241,7 @@ private function validateMenuItemConfig(array $configs)
234241
*
235242
* @param string $value
236243
*
237-
* @return Reference
244+
* @return mixed
238245
*/
239246
private function resolveParameters($value)
240247
{

tests/Rollerworks/Bundle/NavigationBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function testBreadcrumbsWithDefaulted()
4242
'customers' => array(
4343
'parent' => null,
4444
'label' => null,
45+
'options' => array(),
4546
'translator_domain' => 'Breadcrumbs',
47+
'uri' => null,
4648
'expression' => null,
4749
),
4850
),
@@ -81,7 +83,9 @@ public function testBreadcrumbAcceptsService()
8183
'customer' => array(
8284
'parent' => null,
8385
'label' => null,
86+
'options' => array(),
8487
'translator_domain' => 'Breadcrumbs',
88+
'uri' => null,
8589
'service' => array(
8690
'id' => 'acme_customer.navigation',
8791
'method' => 'getBreadcrumb',
@@ -92,7 +96,9 @@ public function testBreadcrumbAcceptsService()
9296
'webhosting' => array(
9397
'parent' => null,
9498
'label' => null,
99+
'options' => array(),
95100
'translator_domain' => 'Breadcrumbs',
101+
'uri' => null,
96102
'service' => array(
97103
'id' => 'acme_webhosting.navigation',
98104
'method' => 'getBreadcrumb',

0 commit comments

Comments
 (0)