Currently, routes can't really cope with forms. You can write a controller or _content controller that calls drupal_get_form() itself, but there's really no equivalent of 'page callback' => 'drupal_get_form' yet. That's a pain, especially since so many of our routes in core are admin forms.
Well, no more!
This patch (coming as soon as I have a nid) adds a new type of wrapping _controller, similar to HtmlPageController, called HtmlFormController. It activates when you have a _form key on your route instead of a _content. It works pretty much the same way as the old page callback trick does; in fact, the body of the only method in HtmlFormController is only a minor modification from drupal_get_form().
There's two key caveats:
- It only works with the new FormInterface-based forms (see http://drupal.org/node/1932058), not with forms defined in a function. Given that this lets us move forms out of .module files and into lazy-loaded classes, I consider this a feature.
- Form arguments are handled with a separate _form_arguments key in the route, but I haven't tested that yet so I'm not sure if it works. :-)
Also, while right now forms are all instantiated straight, there's no reason we cannot let them have the same factory method as controllers as soon asgets in. That would allow us to have nicely injected form builder objects, too. Win!
So far I've just converted one simple admin form, and haven't updated any tests. It may or may not break testbot, but it's after 2 am so I want to get this up for review (and collaborators, please!) and go sleep.
Tim Plunkett: I told you it was possible. :-)
PASSED: [[SimpleTest]]: [MySQL] 52,459 pass(es). View
PASSED: [[SimpleTest]]: [MySQL] 52,487 pass(es). View
FAILED: [[SimpleTest]]: [MySQL] 52,492 pass(es), 1 fail(s), and 6 exception(s). View