Created
May 19, 2014 19:58
-
-
Save anonymous/e2562cc03bc4b284acf6 to your computer and use it in GitHub Desktop.
Book Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Matiit\Bundle\BookBundle\Form\Type; | |
use Doctrine\ORM\EntityRepository; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
class BookType extends AbstractType | |
{ | |
public function __construct($userId) { | |
$this->userId = $userId; | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('title') | |
->add('length') | |
->add('file', 'file', array('required' => true)) | |
->add('category', 'entity', array( | |
'class' => 'MatiitBookBundle:Category', | |
'query_builder' => function(EntityRepository $er) { | |
return $er->createQueryBuilder('c') | |
->where('c.userId = :userId') | |
->setParameter('userId', $this->userId); | |
}, | |
)) | |
->add('save', 'submit'); | |
} | |
public function getName() | |
{ | |
return 'book'; | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) { | |
$resolver->setDefaults(array( | |
'data_class' => 'Matiit\Bundle\BookBundle\Entity\Book', | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment