Sonata\ProductBundle\Model\BaseProductProvider::defineAddBasketForm PHP Method

defineAddBasketForm() public method

This function return the form used in the product view page.
public defineAddBasketForm ( Sonata\Component\Product\ProductInterface $product, FormBuilder $formBuilder, boolean $showQuantity = true, array $options = [] )
$product Sonata\Component\Product\ProductInterface A Sonata product instance
$formBuilder Symfony\Component\Form\FormBuilder Symfony form builder
$showQuantity boolean Specifies if quantity field will be displayed (default true)
$options array An options array
    public function defineAddBasketForm(ProductInterface $product, FormBuilder $formBuilder, $showQuantity = true, array $options = array())
    {
        $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', array('data' => 1))->addModelTransformer($transformer));
        }
    }