mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
add api to add a validation on export elements
Exports elements should implements "ExportElementValidatedInterface"
This commit is contained in:
@@ -55,7 +55,10 @@ class AggregatorType extends AbstractType
|
||||
));
|
||||
|
||||
$filterFormBuilder = $builder->create('form', 'form', array(
|
||||
'compound' => true, 'required' => false));
|
||||
'compound' => true,
|
||||
'required' => false,
|
||||
'error_bubbling' => false
|
||||
));
|
||||
$aggregator->buildForm($filterFormBuilder);
|
||||
|
||||
$builder->add($filterFormBuilder);
|
||||
@@ -66,6 +69,7 @@ class AggregatorType extends AbstractType
|
||||
{
|
||||
$resolver->setRequired('aggregator_alias')
|
||||
->setDefault('compound', true)
|
||||
->setDefault('error_bubbling', false)
|
||||
;
|
||||
}
|
||||
|
||||
|
@@ -29,6 +29,10 @@ use Chill\MainBundle\Export\ExportManager;
|
||||
use Chill\MainBundle\Form\Type\Export\FilterType;
|
||||
use Chill\MainBundle\Form\Type\Export\AggregatorType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraint;
|
||||
use Chill\MainBundle\Export\ExportElementWithValidationInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -57,11 +61,36 @@ class ExportType extends AbstractType
|
||||
{
|
||||
$export = $this->exportManager->getExport($options['export_alias']);
|
||||
|
||||
$exportBuilder = $builder->create(self::EXPORT_KEY, null, array('compound' => true));
|
||||
//if ($export->hasForm()) {
|
||||
$export->buildForm($exportBuilder);
|
||||
//}
|
||||
$builder->add($exportBuilder);
|
||||
$exportOptions = array(
|
||||
'compound' => true,
|
||||
'constraints' => array(
|
||||
//new \Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraint()
|
||||
// new Assert\Callback(array(
|
||||
// 'callback' => function($data, ExecutionContextInterface $context, $payload) use ($export) {
|
||||
// dump('i call back');
|
||||
// }
|
||||
// ))
|
||||
)
|
||||
);
|
||||
|
||||
// add a contraint if required by export
|
||||
/*if ($export instanceof ExportElementWithValidationInterface) {
|
||||
dump('export instance of export element with validation');
|
||||
$exportOptions = array_merge($exportOptions, array(
|
||||
'constraints' => [new Assert\Callback([
|
||||
'callback' => function($data, ExecutionContextInterface $context, $payload) use ($export) {
|
||||
dump('i will execute callback');
|
||||
$export->validateForm($data[self::EXPORT_KEY], $context);
|
||||
}
|
||||
])],
|
||||
'cascade_validation' => true
|
||||
));
|
||||
} */;
|
||||
$exportBuilder = $builder->create(self::EXPORT_KEY/*, FormType::class, $exportOptions*/);
|
||||
|
||||
$export->buildForm($exportBuilder);
|
||||
|
||||
$builder->add($exportBuilder, null, $exportOptions);
|
||||
|
||||
//add filters
|
||||
$filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']);
|
||||
@@ -70,7 +99,10 @@ class ExportType extends AbstractType
|
||||
foreach($filters as $alias => $filter) {
|
||||
$filterBuilder->add($alias, new FilterType($this->exportManager), array(
|
||||
'filter_alias' => $alias,
|
||||
'label' => $filter->getTitle()
|
||||
'label' => $filter->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $filter])
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -85,7 +117,10 @@ class ExportType extends AbstractType
|
||||
foreach($aggregators as $alias => $aggregator) {
|
||||
$aggregatorBuilder->add($alias, new AggregatorType($this->exportManager), array(
|
||||
'aggregator_alias' => $alias,
|
||||
'label' => $aggregator->getTitle()
|
||||
'label' => $aggregator->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $aggregator])
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -109,7 +144,15 @@ class ExportType extends AbstractType
|
||||
$resolver->setRequired(array('export_alias', 'picked_centers'))
|
||||
->setAllowedTypes('export_alias', array('string'))
|
||||
->setDefault('compound', true)
|
||||
->setDefault('constraints', array(
|
||||
//new \Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraint()
|
||||
))
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return FormType::class;
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,10 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Chill\MainBundle\Export\ExportElementWithValidationInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -56,8 +60,11 @@ class FilterType extends AbstractType
|
||||
'required' => false
|
||||
));
|
||||
|
||||
$filterFormBuilder = $builder->create('form', null, array(
|
||||
'compound' => true, 'required' => false));
|
||||
$filterFormBuilder = $builder->create('form', FormType::class, array(
|
||||
'compound' => true,
|
||||
'error_bubbling' => false,
|
||||
'required' => false,
|
||||
));
|
||||
$filter->buildForm($filterFormBuilder);
|
||||
|
||||
$builder->add($filterFormBuilder);
|
||||
@@ -68,6 +75,7 @@ class FilterType extends AbstractType
|
||||
{
|
||||
$resolver->setRequired('filter_alias')
|
||||
->setDefault('compound', true)
|
||||
->setDefault('error_bubbling', false)
|
||||
;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user