<?php

namespace Site\FrontendBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityRepository;
use Site\FrontendBundle\Form\Extension;


class UploadType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('idCategory', 'entity', array(
                'class' => 'FrontendBundle:Categories',
                'empty_value' => 'Choose the category *',
                'property' => 'nameEng',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('u')
                        ->orderBy('u.nameeng', 'ASC');
                },
                'empty_data'  => 1,
            ))
            ->add('file', 'file', array(
                'data_class' => null,
            ))
            ->add('nameEng', 'text')
            ->add('message', 'textarea')
            ->add('web', 'text', array(
                'required' => false)
            )
            ->add('metadata', 'text', array(
                  'required' => false)
            )
        ;

        if ($builder->getData()->getId()) { // or !getId()
            $builder->add('delete', 'checkbox'); // or whatever
        }
    }
    public function getName()
    {
        return 'site_frontendbundle_uploadtype';
    }
}
?>