<?php
namespace WAM\Bundle\BlockBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use WAM\Bundle\BlockBundle\Entity\Types\CollectionBlock;
/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wam_block');
$rootNode
->children()
->scalarNode('class')->defaultValue('WAM\Bundle\BlockBundle\Entity\AbstractBlock')->end()
->arrayNode('custom_types')
->defaultValue(array())
->prototype('scalar')->end()
->end()
->arrayNode('templates')
->useAttributeAsKey('namespace', true)
->prototype('variable')
->validate()
->ifTrue(function ($value) {
if (!is_array($value)) {
return true;
}
foreach ($value as $item) {
if (!in_array('source', array_keys($item))) {
return true;
}
if (!in_array('name', array_keys($item))) {
return true;
}
if (!in_array('icon_class', array_keys($item))) {
return true;
}
}
})
->thenInvalid('Invalid templates configuration')
->end()
->end()
->end()
->arrayNode('global_templates')
->defaultValue(array())
->prototype('array')
->children()
->scalarNode('name')->end()
->scalarNode('icon_class')->end()
->scalarNode('source')->end()
->end()
->end()
->end()
->arrayNode('ckeditor')
->addDefaultsIfNotSet()
->children()
->scalarNode('default')
->defaultValue('default')->end()
->arrayNode('blocks')
->defaultValue(array())
->prototype('scalar')->end()
->end()
->end()
->end()
->arrayNode('collection_block')
->addDefaultsIfNotSet()
->children()
->arrayNode('entities')
->defaultValue(array())
->useAttributeAsKey('namespace')
->prototype('array')
->children()
->scalarNode('name_to_show')->end()
->scalarNode('prefix')->end()
->arrayNode('order_fields')
->defaultValue(array())
->prototype('scalar')->end()
->end()
->arrayNode('special_fields')
->useAttributeAsKey('entity_special_field')
->prototype('array')
->children()
->scalarNode('name')->end()
->scalarNode('type')->end()
->scalarNode('class')->end()
->scalarNode('choices_class')->end()
->scalarNode('choices_static_method')->end()
->scalarNode('operator')->defaultValue(CollectionBlock::OPERATOR_EQUALS)->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
}