mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
set some fields visibility as configurable
Some fields can now be hidden through configuration
This commit is contained in:
@@ -31,10 +31,25 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
||||
// set configuration for validation
|
||||
$container->setParameter('chill_person.validation.birtdate_not_before',
|
||||
$config['validation']['birthdate_not_after']);
|
||||
|
||||
$this->handlePersonFieldsParameters($container, $config['person_fields']);
|
||||
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
|
||||
private function handlePersonFieldsParameters(ContainerBuilder $container, $config)
|
||||
{
|
||||
if (array_key_exists('enabled', $config)) {
|
||||
unset($config['enabled']);
|
||||
}
|
||||
|
||||
$container->setParameter('chill_person.person_fields', $config);
|
||||
|
||||
foreach ($config as $key => $value) {
|
||||
$container->setParameter('chill_person.person_fields.'.$key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
private function declarePersonAsCustomizable (ContainerBuilder $container)
|
||||
{
|
||||
@@ -66,6 +81,18 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
||||
$asseticConfig['bundles'][] = 'ChillPersonBundle';
|
||||
$container->prependExtensionConfig('assetic',
|
||||
array('bundles' => array('ChillPersonBundle')));
|
||||
|
||||
//add person_fields parameter as global
|
||||
$chillPersonConfig = $container->getExtensionConfig($this->getAlias());
|
||||
$config = $this->processConfiguration(new Configuration(), $chillPersonConfig);
|
||||
$twigConfig = array(
|
||||
'globals' => array(
|
||||
'chill_person' => array(
|
||||
'fields' => $config['person_fields']
|
||||
)
|
||||
)
|
||||
);
|
||||
$container->prependExtensionConfig('twig', $twigConfig);
|
||||
|
||||
$this-> declarePersonAsCustomizable($container);
|
||||
|
||||
|
@@ -27,40 +27,70 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->arrayNode('search')
|
||||
->canBeDisabled()
|
||||
->arrayNode('search')
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->booleanNode('use_double_metaphone')
|
||||
->defaultFalse()
|
||||
->end()
|
||||
->booleanNode('use_trigrams')
|
||||
->defaultFalse()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation')
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->scalarNode('birthdate_not_after')
|
||||
->info($this->validationBirthdateNotAfterInfos)
|
||||
->defaultValue('P1D')
|
||||
->validate()
|
||||
->ifTrue(function($period) {
|
||||
try {
|
||||
$interval = new \DateInterval($period);
|
||||
} catch (\Exception $ex) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
->thenInvalid('Invalid period for birthdate validation : "%s" '
|
||||
. 'The parameter should match duration as defined by ISO8601 : '
|
||||
. 'https://en.wikipedia.org/wiki/ISO_8601#Durations')
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
->booleanNode('use_double_metaphone')
|
||||
->defaultFalse()
|
||||
->end() // use_double_metaphone, parent = children for 'search'
|
||||
->booleanNode('use_trigrams')
|
||||
->defaultFalse()
|
||||
->end() // use_trigrams, parent = children of 'search'
|
||||
->end() //children for 'search', parent = array node 'search'
|
||||
->end() // array 'search', parent = children of root
|
||||
->arrayNode('validation')
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->scalarNode('birthdate_not_after')
|
||||
->info($this->validationBirthdateNotAfterInfos)
|
||||
->defaultValue('P1D')
|
||||
->validate()
|
||||
->ifTrue(function($period) {
|
||||
try {
|
||||
$interval = new \DateInterval($period);
|
||||
} catch (\Exception $ex) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
->thenInvalid('Invalid period for birthdate validation : "%s" '
|
||||
. 'The parameter should match duration as defined by ISO8601 : '
|
||||
. 'https://en.wikipedia.org/wiki/ISO_8601#Durations')
|
||||
->end() // birthdate_not_after, parent = children of validation
|
||||
|
||||
->end() // children for 'validation', parent = validation
|
||||
->end() //validation, parent = children of root
|
||||
->end() // children of root, parent = root
|
||||
->arrayNode('person_fields')
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->append($this->addFieldNode('place_of_birth'))
|
||||
->append($this->addFieldNode('email'))
|
||||
->append($this->addFieldNode('phonenumber'))
|
||||
->append($this->addFieldNode('nationality'))
|
||||
->append($this->addFieldNode('country_of_birth'))
|
||||
->append($this->addFieldNode('marital_status'))
|
||||
->append($this->addFieldNode('spoken_languages'))
|
||||
->end() //children for 'person_fields', parent = array 'person_fields'
|
||||
->end() // person_fields, parent = children of root
|
||||
->end() // children of 'root', parent = root
|
||||
;
|
||||
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
private function addFieldNode($key)
|
||||
{
|
||||
$tree = new TreeBuilder();
|
||||
$node = $tree->root($key, 'enum');
|
||||
|
||||
$node
|
||||
->values(array('hidden', 'visible'))
|
||||
->defaultValue('visible')
|
||||
->info("If the field $key must be shown")
|
||||
->end();
|
||||
//var_dump($node);
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user