Skip to content

Commit

Permalink
Merge pull request #13 from jbouzekri/netfarma/master
Browse files Browse the repository at this point in the history
allow "extras" params in config
  • Loading branch information
jbouzekri authored Aug 28, 2016
2 parents 41cbd45 + d147501 commit 9a02b16
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Config/Definition/Builder/MenuNodeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public function menuNodeHierarchy($depth = 10)
->prototype('scalar')
->end()
->end()
->arrayNode('extras')
->prototype('scalar')
->end()
->end()
->menuNode('children')->menuNodeHierarchy($depth - 1)
->end()
->end();
Expand Down
1 change: 0 additions & 1 deletion DependencyInjection/JbConfigKnpMenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function load(array $configs, ContainerBuilder $container)
$container
->getDefinition('jb_config.menu.provider')
->addArgument($configuredMenus);

}

/**
Expand Down
5 changes: 5 additions & 0 deletions Provider/ConfigurationMenuProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ protected function createItem($parentItem, $name, $configuration)
if (!empty($configuration['labelAttributes'])) {
$item->setLabelAttributes($configuration['labelAttributes']);
}

// set extras
if (!empty($configuration['extras'])) {
$item->setExtras($configuration['extras']);
}

// set display
if (isset($configuration['display'])) {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ my_mega_menu:
display: boolean to hide the item
displayChildren: boolean to hide the children
roles: array of item (string roles) passed to isGranted securityContext method to check if user has rights in menu items
extras: An array of extra parameters (for example icon img, additional content etc.)
children: # An array of subitems
second_level_item:
label: My second level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ main:
test: test4
display: false
displayChildren: false
extras:
key1: value1
key2: value2
four_item:
label: "Four Item Label"
order: 40
five_item:
label: "Five Item Label"
order: 40
order: 40
4 changes: 3 additions & 1 deletion Tests/DependencyInjection/NavigationConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static function buildRandomMenuItem($number = 1)
'display' => true,
'displayChildren' => true,
'children' => array(),
'roles' => array()
'roles' => array(),
'extras' => array()
);
}

Expand Down Expand Up @@ -121,6 +122,7 @@ public function getInvalidTypeData()
array( array('tree' => array('item1' => array('displayChildren' => array()))) ),
array( array('tree' => array('item1' => array('children' => ''))) ),
array( array('tree' => array('item1' => array('labelAttributes' => ''))) ),
array( array('tree' => array('item1' => array('extras' => ''))) ),
);
}

Expand Down
5 changes: 5 additions & 0 deletions Tests/Provider/ConfigurationMenuProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public function testGet()
$menu->getChild('third_item')->getDisplayChildren(),
'Third item display children'
);
$this->assertEquals(
array('key1' => 'value1', 'key2' => 'value2'),
$menu->getChild('third_item')->getExtras(),
'Third item extras'
);

$position = 0;
foreach ($menu->getChildren() as $key => $item) {
Expand Down

0 comments on commit 9a02b16

Please sign in to comment.