Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e6286c7

Browse filesBrowse files
committed
Merge pull request symfony#2930 from Burgov/remove_no_longer_necessary_factory
Remove no longer necessary factory
2 parents 2f69d3a + 3364c8a commit e6286c7
Copy full SHA for e6286c7

File tree

Expand file treeCollapse file tree

1 file changed

+10
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-6
lines changed

‎cookbook/form/dynamic_form_modification.rst

Copy file name to clipboardExpand all lines: cookbook/form/dynamic_form_modification.rst
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,9 @@ and fill in the listener logic::
270270
);
271271
}
272272

273-
$factory = $builder->getFormFactory();
274-
275273
$builder->addEventListener(
276274
FormEvents::PRE_SET_DATA,
277-
function(FormEvent $event) use($user, $factory){
275+
function(FormEvent $event) use ($user) {
278276
$form = $event->getForm();
279277

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

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

375-
class FriendMessageController extends Controller
373+
use Symfony\Component\DependencyInjection\ContainerAware;
374+
375+
class FriendMessageController extends ContainerAware
376376
{
377377
public function newAction(Request $request)
378378
{
379-
$form = $this->createForm('acme_friend_message');
379+
$form = $this->get('form.factory')->create('acme_friend_message');
380380

381381
// ...
382382
}
383383
}
384384

385+
If you extend the ``Symfony\Bundle\FrameworkBundle\Controller\Controller`` class, you can simply call::
386+
387+
$form = $this->createForm('acme_friend_message');
388+
385389
You can also easily embed the form type into another form::
386390

387391
// inside some other "form type" class

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.