If we force modules to put their include files in a /includes subfolder, we can simplify a lot of code. Module files are always loaded, so if a callback file is specified, we will always know it's in the callback module's /includes folder. If we go even further, we can force a file name format (modulename.includename.inc), so we'd only need part of the filename and the module name to include a file. module_load_include() could be rewritten to this:
function drupal_include($name, $module = 'system') {
if (function_exists('drupal_get_path')) {
$file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/includes/$module.$name.inc";
if (is_file($file)) {
require_once $file;
return $file;
}
}
return FALSE;
}
As you can see $module defaults to System.module. This would have the greatest impact if we move all files from /includes to /modules/system/includes.
So far I can only think of one big pro, which is clarity & consistency. Please post any advantages or disadvantages this approach might have.
Comments
Comment #1
xanohook_hook_info() could then be changed as well. The 'group' property in the return value would then actually be like $name as proposed above. This would IMHO make more sense, because the code in an include file doesn't necessarily have to be a single group.
Comment #2
swentel commentedmarked #950420: Includes files for modules and in fixed folders only as a duplicate.
Comment #15
quietone commentedSince include files are being removed, #3097045: [META] Provide modern replacements for and deprecate the legacy include files, I am closing this as outdated.