public function defineAddBasketForm(ProductInterface $product, FormBuilder $formBuilder, $showQuantity = true, array $options = [])
    {
        $basketElement = $this->createBasketElement($product);

        // create the product form
        $formBuilder
            ->setData($basketElement)
            ->add('productId', 'hidden');

        if ($showQuantity) {
            $formBuilder->add('quantity', 'integer');
        } else {
            $transformer = new QuantityTransformer();
            $formBuilder->add(
                    $formBuilder->create('quantity', 'hidden', ['data' => 1])
                                ->addModelTransformer($transformer)
            );
        }
    }
public function defineAddBasketForm(ProductInterface $product, FormBuilder $formBuilder, $showQuantity = true, array $options = [])
    {
        $basketElement = $this->createBasketElement($product);

        // create the product form
        $formBuilder
            ->setData($basketElement)
            ->add('productId', 'hidden');

        if ($showQuantity) {
            $formBuilder->add('quantity', 'integer');
        } else {
            $transformer = new QuantityTransformer();
            $formBuilder->add(
                    $formBuilder->create('quantity', 'hidden', ['data' => 1])
                                ->addModelTransformer($transformer)
            );
        }
    }
public function defineAddBasketForm ( ProductInterface $ product , FormBuilder $ formBuilder , $ showQuantity = true , array $ options = [ ] ) { $ basketElement = $ this -> createBasketElement ( $ product ) ; // create the product form $ formBuilder -> setData ( $ basketElement ) -> add ( 'productId' , 'hidden' ) ; if ( $ showQuantity ) { $ formBuilder -> add ( 'quantity' , 'integer' ) ; } else { $ transformer = new QuantityTransformer ( ) ; $ formBuilder -> add ( $ formBuilder -> create ( 'quantity' , 'hidden' , [ 'data' => 1 ] ) -> addModelTransformer ( $ transformer ) ) ; } }
This function return the form used in the product view page.

@param \Sonata\Component\Product\ProductInterface $product      A Sonata product instance
@param \Symfony\Component\Form\FormBuilder        $formBuilder  Symfony form builder
@param bool                                       $showQuantity Specifies if quantity field will be displayed (default true)
@param array                                      $options      An options array
This function return the form used in the product view page .