[development] inferring which file to include based on page callback array

Moshe Weitzman weitzman at tejasa.com
Mon Jun 11 19:05:56 UTC 2007



Larry Garfield wrote:
> On Sun, 10 Jun 2007 22:13:04 -0400, Moshe Weitzman <weitzman at tejasa.com> wrote:
>>> I ran into this issue in the context of "which file do we need to include
>> so
>>> that this function becomes available".  The file was module-dependent. 
>> The
>>> function then did not exist yet, so module_implements() and
>> function_exists()
>>> won't work.
>> many keep saying that, but there is an easy fix. just use
>> module_invoke('og', 'vocab') if thats what is meant. then module_invoke
>> can do the needed includes. module invoke makes explicit the module that
>> owns the function.
> 
> That again assumes that the code running that line knows which part of the function is the module and which isn't.  If you are given the string:
> 
> "foo_bar_baz_ugh_agh"
> 
> Is that the foo module, function bar_baz_ugh_agh?  Or the foo_bar_baz module function ug_agh?  Or foo_bar_baz_ugh module function agh?  That cannot be determined without a guess-and-check method.  That's precisely why I didn't go that route for the menu-split patch.
>

You are assuming that I am assuming :). I hadn't spelled it all out yet ...

Right now, hook_menu() accepts only a string as the value of 'page 
callback' element. lets say we allow a simple array with 2 values. the 
values will be the first two arguments of module_invoke(). in this case 
  menu_execute_active_item() would then perform a module_invoke() 
instead of a direct call_user_func_array(). then the including of the 
right file gets done in module_invoke(), not directly specified in the 
menu item definition.

here is an example from current HEAD and how I propose. Note that 'file' 
element is gone, and we know definitively that it belongs to 
system.module based on the page callback value.

CURRENT
   $items['admin/build'] = array(
     'title' => 'Site building',
     'page callback' => 'system_admin_menu_block_page',
     'file' => 'system.admin.inc',

PROPOSED
   $items['admin/build'] = array(
     'title' => 'Site building',
     'page callback' => array('system, 'admin_menu_block_page'),
   (

Note that we may still have to support a string as a page callback (i 
think) for non module defined callbacks.



More information about the development mailing list