Skip to content

Remove no longer necessary factory #2930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cookbook/form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,9 @@ and fill in the listener logic::
);
}

$factory = $builder->getFormFactory();

$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function(FormEvent $event) use($user, $factory){
function(FormEvent $event) use ($user) {
$form = $event->getForm();

$formOptions = array(
Expand All @@ -289,7 +287,7 @@ and fill in the listener logic::

// create the field, this is similar the $builder->add()
// field name, field type, data, options
$form->add($factory->createNamed('friend', 'entity', null, $formOptions));
$form->add('friend', 'entity', $formOptions);
}
);
}
Expand Down Expand Up @@ -372,16 +370,22 @@ it with :ref:`dic-tags-form-type`.
If you wish to create it from within a controller or any other service that has
access to the form factory, you then use::

class FriendMessageController extends Controller
use Symfony\Component\DependencyInjection\ContainerAware;

class FriendMessageController extends ContainerAware
{
public function newAction(Request $request)
{
$form = $this->createForm('acme_friend_message');
$form = $this->get('form.factory')->create('acme_friend_message');

// ...
}
}

If you extend the ``Symfony\Bundle\FrameworkBundle\Controller\Controller`` class, you can simply call::

$form = $this->createForm('acme_friend_message');

You can also easily embed the form type into another form::

// inside some other "form type" class
Expand Down