[development] The Drupal Diet - Making bootstrap faster

Earl Miles merlin at logrus.com
Sat May 5 02:33:57 UTC 2007


Larry Garfield wrote:
> On Fri, 04 May 2007 11:15:12 -0700, Earl Miles <merlin at logrus.com> wrote:
>> Larry Garfield wrote:
>>> 1) Forms that are used as a page handler, if factored out to separate
>> files,
>>> may never be called from drupal_execute().  I do not consider this
>>> acceptable.
>> This doesn't follow. If I put my form in foo.pages.inc and use
>> drupal_get_form
>> as the callback, and provide my include so that my foo.pages.inc is loaded
>> when
>> that menu is hit, my form will be there. This, of course, isn't true if
>> this
>> form is also available in a non-page-context, which can happen, but in
>> that
>> case the form should be embedded into the .module anyway.
> 
> drupal_execute() is a non-page context.  

So is almost every other API call.

> Take for example node_type_form, the form function for which is node_form.
> It's a non-settings-page form that is used as a parameter to a callback on
> drupal_get_form, and is rarely used but reasonably large so it's a great
> candidate for factoring out of the main node.module file.

Sure, by itself it is. But node_form is, in core Drupal. only used via node_add 
and node_edit. Factor those out into their own pages. node forms, however, are 
a bad example because they are part of a fairly complex specialized hook system 
which isn't going to be addressed well by just this patch.

> If we factor it out into a pages include file for the node module, then it
> gets loaded when a user visits admin/content/types/page. Great.
> 
> What happens, though, if someone calls drupal_execute('node_type_form',
> ...)?
> How does the system know where to find that form and how to load it if
> drupal_execute() doesn't have some knowledge of where forms live? Either
> drupal_get_form() and drupal_execute() have to be able to dynamically load the
> form or that form now becomes inaccessible except through the page handler.

Well. To be honest I've been pretty against a lot of the uses of drupal_execute 
that everyone is so fond of, because it's tying the form to the object which I 
*hate*, strongly, and I simply don't understand why everyone loves it, beyond 
getting to cheat a little on validation. So I'm not really *for* this kind of 
thing; IMO if you're going to use drupal_execute('node_type_form') you should 
probably have to call an include prior to using it, or node.module includes an 
API that does that so the user doesn't have to.




More information about the development mailing list