mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 16:13:50 +00:00
Add column option, definition in config & adapt form
Exemple for configuration : ``` chill_custom_fields: customizables_entities: - class: Chill\ReportBundle\Entity\Report name: ReportEntity options: summary_fields: {key: abc, form_type: text, form_options: { required: false }} ```
This commit is contained in:
@@ -6,6 +6,8 @@ use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
|
||||
|
||||
class CustomFieldsGroupType extends AbstractType
|
||||
@@ -32,18 +34,50 @@ class CustomFieldsGroupType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
//prepare translation
|
||||
$customizableEntites = array();
|
||||
$entities = array();
|
||||
$customizableEntities = array();
|
||||
|
||||
foreach($this->customizableEntities as $key => $definition) {
|
||||
$customizableEntites[$definition['class']] = $this->translator->trans($definition['name']);
|
||||
$entities[$definition['class']] = $this->translator->trans($definition['name']);
|
||||
$customizableEntities[$definition['class']] = $definition;
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('name', 'translatable_string')
|
||||
->add('entity', 'choice', array(
|
||||
'choices' => $customizableEntites
|
||||
'choices' => $entities
|
||||
))
|
||||
;
|
||||
|
||||
$builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event)
|
||||
use ($customizableEntities, $builder){
|
||||
$form = $event->getForm();
|
||||
$group = $event->getData();
|
||||
|
||||
if (count($customizableEntities[$group->getEntity()]['options']) > 0) {
|
||||
$optionBuilder = $builder
|
||||
->getFormFactory()
|
||||
->createBuilderForProperty(
|
||||
'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup',
|
||||
'options'
|
||||
)
|
||||
->create('options', null, array(
|
||||
'compound' => true,
|
||||
'auto_initialize' => false,
|
||||
'required' => false)
|
||||
);
|
||||
}
|
||||
|
||||
foreach($customizableEntities[$group->getEntity()]['options'] as $key => $option) {
|
||||
$optionBuilder
|
||||
->add($key, $option['form_type'], $option['form_options'])
|
||||
;
|
||||
}
|
||||
if (isset($optionBuilder) && $optionBuilder->count() > 0) {
|
||||
$form->add($optionBuilder->getForm());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user