Skip to content

Instantly share code, notes, and snippets.

@webmozart
Created February 24, 2011 20:31
Show Gist options
  • Select an option

  • Save webmozart/842827 to your computer and use it in GitHub Desktop.

Select an option

Save webmozart/842827 to your computer and use it in GitHub Desktop.
<?php
namespace Sensio\HelloBundle;
use Symfony\Component\Form\FormFactory;
use Sensio\HelloBundle\Entity\Post;
use Sensio\HelloBundle\Entity\Comment;
class HelloFormFactory
{
private $factory;
public function __construct(FormFactory $factory)
{
$this->factory = $factory;
}
public function getPostForm(Post $post = null, $name = 'post')
{
$factory = $this->factory;
return $factory->getForm('post')
->setDataClass('Sensio\HelloBundle\Entity\Post')
->setData($post)
->add('title')
->add('content')
->add('abstract')
->add($factory->getCheckboxField('enabled'))
->add($factory->getDateField('publicationDateStart'))
->add($factory->getChoiceField('commentsDefaultStatus', array(
'choices' => Comment::getStatusCodes(),
)))
->add($factory->getEntityChoiceField('tags', array(
'class' => 'Sensio\HelloBundle\Entity\Tag',
'expanded' => true,
'multiple' => true,
)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment