src/Flowcode/ShopBundle/Form/FilterShopType.php
/**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
@param FormBuilderInterface $builder
@param array $options
@param FormBuilderInterface $builder @param array $options
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('price', Filters\NumberRangeFilterType::class, array(
                'label' => false,
                'left_number_options' => array(
                    'attr' => array(
                        'placeholder' => 'Precio desde'
                    ),
                    'condition_operator' => FilterOperands::OPERATOR_GREATER_THAN_EQUAL
                ),
                'right_number_options' => array(
                    'attr' => array(
                        'placeholder' => 'Precio hasta'
                    ),
                    'condition_operator' => FilterOperands::OPERATOR_LOWER_THAN_EQUAL
                ),
            ))
            ->add('category', Filters\EntityFilterType::class, array(
                'class' => Category::class,
                'choices' => $this->categoryService->findByRoot("product"),
                'choice_label' => function (Category $category) {
                    if (!is_null($category->getParent())) {
                        return $category->getName();
                    }
                    return null;
                },
                'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                    if ($values['value']->isEmpty()) {
                        return null;
                    }
                    $paramName = sprintf('p_%s', str_replace('.', '_', $field));
                    $expression = $filterQuery->getExpr()->in($field, ':' . $paramName);
                    $expression .= ' OR ' . $filterQuery->getExpr()->in('cat.parent', ':' . $paramName);
                    $parameters = array($paramName => $values['value']);
                    return $filterQuery->createCondition($expression, $parameters);
                },
                'multiple' => true,
                'empty_data' => null
            ));
    }
public function buildForm ( FormBuilderInterface $ builder , array $ options ) { $ builder -> add ( 'price' , Filters \ NumberRangeFilterType :: class , array ( 'label' => false , 'left_number_options' => array ( 'attr' => array ( 'placeholder' => 'Precio desde' ) , 'condition_operator' => FilterOperands :: OPERATOR_GREATER_THAN_EQUAL ) , 'right_number_options' => array ( 'attr' => array ( 'placeholder' => 'Precio hasta' ) , 'condition_operator' => FilterOperands :: OPERATOR_LOWER_THAN_EQUAL ) , ) ) -> add ( 'category' , Filters \ EntityFilterType :: class , array ( 'class' => Category :: class , 'choices' => $ this -> categoryService -> findByRoot ( " product " ) , 'choice_label' => function ( Category $ category ) { if ( ! is_null ( $ category -> getParent ( ) ) ) { return $ category -> getName ( ) ; } return null ; } , 'apply_filter' => function ( QueryInterface $ filterQuery , $ field , $ values ) { if ( $ values [ 'value' ] -> isEmpty ( ) ) { return null ; } $ paramName = sprintf ( 'p_%s' , str_replace ( '.' , '_' , $ field ) ) ; $ expression = $ filterQuery -> getExpr ( ) -> in ( $ field , ':' . $ paramName ) ; $ expression .= ' OR ' . $ filterQuery -> getExpr ( ) -> in ( 'cat.parent' , ':' . $ paramName ) ; $ parameters = array ( $ paramName => $ values [ 'value' ] ) ; return $ filterQuery -> createCondition ( $ expression , $ parameters ) ; } , 'multiple' => true , 'empty_data' => null ) ) ; }
@param FormBuilderInterface $builder
 @param array $options
@param FormBuilderInterface $builder @param array $options