diff --git a/Form/Type/Export/AggregatorType.php b/Form/Type/Export/AggregatorType.php index c91e2f7be..dd2125546 100644 --- a/Form/Type/Export/AggregatorType.php +++ b/Form/Type/Export/AggregatorType.php @@ -34,20 +34,15 @@ use Chill\MainBundle\Export\ExportManager; */ class AggregatorType extends AbstractType { - /** - * - * @var \ExportManager - */ - private $exportManager; - public function __construct(ExportManager $exportManager) + public function __construct() { - $this->exportManager = $exportManager; } public function buildForm(FormBuilderInterface $builder, array $options) { - $aggregator = $this->exportManager->getAggregator($options['aggregator_alias']); + $exportManager = $options['export_manager']; + $aggregator = $exportManager->getAggregator($options['aggregator_alias']); $builder ->add('enabled', CheckboxType::class, array( @@ -70,6 +65,7 @@ class AggregatorType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired('aggregator_alias') + ->setRequired('export_manager') ->setDefault('compound', true) ->setDefault('error_bubbling', false) ; diff --git a/Form/Type/Export/ExportType.php b/Form/Type/Export/ExportType.php index becc6c257..36a72d0c2 100644 --- a/Form/Type/Export/ExportType.php +++ b/Form/Type/Export/ExportType.php @@ -79,9 +79,12 @@ class ExportType extends AbstractType $filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']); $filterBuilder = $builder->create(self::FILTER_KEY, FormType::class, array('compound' => true)); + dump($this->exportManager); + foreach($filters as $alias => $filter) { - $filterBuilder->add($alias, new FilterType($this->exportManager), array( + $filterBuilder->add($alias, FilterType::class, array( 'filter_alias' => $alias, + 'export_manager' => $this->exportManager, 'label' => $filter->getTitle(), 'constraints' => array( new ExportElementConstraint(['element' => $filter]) @@ -94,12 +97,13 @@ class ExportType extends AbstractType //add aggregators $aggregators = $this->exportManager ->getAggregatorsApplyingOn($export, $options['picked_centers']); - $aggregatorBuilder = $builder->create(self::AGGREGATOR_KEY, FormType::class, + $aggregatorBuilder = $builder->create(self::AGGREGATOR_KEY, FormType::class, array('compound' => true)); foreach($aggregators as $alias => $aggregator) { - $aggregatorBuilder->add($alias, new AggregatorType($this->exportManager), array( + $aggregatorBuilder->add($alias, AggregatorType::class, array( 'aggregator_alias' => $alias, + 'export_manager' => $this->exportManager, 'label' => $aggregator->getTitle(), 'constraints' => array( new ExportElementConstraint(['element' => $aggregator]) diff --git a/Form/Type/Export/FilterType.php b/Form/Type/Export/FilterType.php index bd23e664a..21f1bcd48 100644 --- a/Form/Type/Export/FilterType.php +++ b/Form/Type/Export/FilterType.php @@ -30,53 +30,49 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Form\Extension\Core\Type\FormType; /** - * + * * * @author Julien Fastré */ class FilterType extends AbstractType { - /** - * - * @var \ExportManager - */ - private $exportManager; - const ENABLED_FIELD = 'enabled'; - - public function __construct(ExportManager $exportManager) + + public function __construct() { - $this->exportManager = $exportManager; } - + public function buildForm(FormBuilderInterface $builder, array $options) { - $filter = $this->exportManager->getFilter($options['filter_alias']); - + + $exportManager = $options['export_manager']; + $filter = $exportManager->getFilter($options['filter_alias']); + $builder ->add(self::ENABLED_FIELD, CheckboxType::class, array( 'value' => true, 'data' => false, 'required' => false )); - + $filterFormBuilder = $builder->create('form', FormType::class, array( - 'compound' => true, + 'compound' => true, 'error_bubbling' => false, 'required' => false, )); $filter->buildForm($filterFormBuilder); - + $builder->add($filterFormBuilder); - + } - + public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired('filter_alias') + ->setRequired('export_manager') ->setDefault('compound', true) ->setDefault('error_bubbling', false) ; } - + }