Bundle/CoreBundle/Form/WidgetType.php
protected function addCriteriasFields($builder, $options)
    {
        $builder->add('criterias', CriteriaCollectionType::class, [
            'label'         => 'victoire.widget.type.criterias.label',
            'entry_type'    => CriteriaType::class,
            'required'      => false,
            'entry_options' => [
                'dataSources' => $options['dataSources'],
            ],
        ]);
        $builder->addEventListener(
            FormEvents::PRE_SET_DATA,
            function (FormEvent $event) use ($options) {
                $dataSources = $options['dataSources']->getDataSources();
                $widget = $event->getData();
                foreach ($dataSources as $alias => $dataSource) {
                    if (!$widget->hasCriteriaNamed($alias)) {
                        $criteria = new Criteria();
                        $criteria->setName($alias);
                        $widget->addCriteria($criteria);
                    }
                }
            }
        );
        $builder->addEventListener(
            FormEvents::POST_SUBMIT,
            function (FormEvent $event) use ($options) {
                $widget = $event->getData();
                /** @var Criteria $criteria */
                foreach ($widget->getCriterias() as $criteria) {
                    if ($criteria->getValue() === null) {
                        $widget->removeCriteria($criteria);
                    }
                }
            }
        );
    }
protected function addCriteriasFields($builder, $options)
    {
        $builder->add('criterias', CriteriaCollectionType::class, [
            'label'         => 'victoire.widget.type.criterias.label',
            'entry_type'    => CriteriaType::class,
            'required'      => false,
            'entry_options' => [
                'dataSources' => $options['dataSources'],
            ],
        ]);
        $builder->addEventListener(
            FormEvents::PRE_SET_DATA,
            function (FormEvent $event) use ($options) {
                $dataSources = $options['dataSources']->getDataSources();
                $widget = $event->getData();
                foreach ($dataSources as $alias => $dataSource) {
                    if (!$widget->hasCriteriaNamed($alias)) {
                        $criteria = new Criteria();
                        $criteria->setName($alias);
                        $widget->addCriteria($criteria);
                    }
                }
            }
        );
        $builder->addEventListener(
            FormEvents::POST_SUBMIT,
            function (FormEvent $event) use ($options) {
                $widget = $event->getData();
                /** @var Criteria $criteria */
                foreach ($widget->getCriterias() as $criteria) {
                    if ($criteria->getValue() === null) {
                        $widget->removeCriteria($criteria);
                    }
                }
            }
        );
    }
protected function addCriteriasFields ( $ builder , $ options ) { $ builder -> add ( 'criterias' , CriteriaCollectionType :: class , [ 'label' => 'victoire.widget.type.criterias.label' , 'entry_type' => CriteriaType :: class , 'required' => false , 'entry_options' => [ 'dataSources' => $ options [ 'dataSources' ] , ] , ] ) ; $ builder -> addEventListener ( FormEvents :: PRE_SET_DATA , function ( FormEvent $ event ) use ( $ options ) { $ dataSources = $ options [ 'dataSources' ] -> getDataSources ( ) ; $ widget = $ event -> getData ( ) ; foreach ( $ dataSources as $ alias => $ dataSource ) { if ( ! $ widget -> hasCriteriaNamed ( $ alias ) ) { $ criteria = new Criteria ( ) ; $ criteria -> setName ( $ alias ) ; $ widget -> addCriteria ( $ criteria ) ; } } } ) ; $ builder -> addEventListener ( FormEvents :: POST_SUBMIT , function ( FormEvent $ event ) use ( $ options ) { $ widget = $ event -> getData ( ) ; /** @var Criteria $criteria */ foreach ( $ widget -> getCriterias ( ) as $ criteria ) { if ( $ criteria -> getValue ( ) === null ) { $ widget -> removeCriteria ( $ criteria ) ; } } } ) ; }
Add the criterias fields.

@param FormBuilderInterface $builder
@param array                $options
Add the criterias fields .