I'm trying to create a bundle to manage a menu which can be configured via config files.
So I have wrote some configuration constraints in my class DependencyInjection\Configuration.
The needed configuration is an array of items which must be added to the menu. Each item can have 3 different types (link, link_notification, widget). And for each type, item needs other attributes (like route, label, etc.).
Example of configuration:
menu:
utilities:
- { type: link, icon: icon_name, label: text, route: { name: route_name, params: {} } }
- { type: link_notification, notification: notification_text }
- { type: widget, controller: controller_name }
I'm stuck because I can't find how to define different array constraints for each type.
I can't find a way to translate condition:
IF type == "link" THEN scalarNode "icon" IS REQUIRED AND scalarNode "label" IS REQUIRED ...
Configuration file looks like this:
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('aiomedia_menu');
$rootNode
->children()
->arrayNode('utilities')
->prototype('array')
->children()
->enumNode('type')
->values(array ('link', 'link_notification', 'widget'))
->isRequired()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
I have seen methods ->ifXXX() [...] ->then() in Symfony2 documentation, but I can't figure out how to use them in this context.