I would like to see this function in D8:
function module_include($module, $file, $dir = 'includes', $type = 'inc')
the $file parameter could be renamed to something more appropriate, but not sure what that could be
-----
I never understood why does the module_load_include has the file type as first parameter, and why is that the first parameter.
it is good to load files which look like module_name.something
like
views.module = module_load_include('module', 'views')
views.install = module_load_include('install', 'views') // but this is wrong, as module_load_install() needs to be used
but it is quite unusable for anything else:
module_load_include('inc', 'search', 'search.pages');
module_load_include('inc', 'coder_upgrade', 'includes/menu');
module_load_include('inc', 'coder_upgrade', 'conversions/list');
these should be:
module_include('search', 'search.pages', '');
module_include('search', 'pages'); // if the file would be in the right place: /includes/pages.inc
module_include('coder_upgrade', 'menu');
module_include('coder_upgrade', 'list', 'conversions');
then if the module needs it can have wrapper functions (to write less code) like
function coder_upgrade_include($file) {
module_include('coder_upgrade', $file);
}
function coder_upgrade_include_conversion($file) {
module_include('coder_upgrade', $file, 'conversions');
}
As I see for module_name.something I can only give two examples: module_name.module; module_name.inc
I never needed to include module_name.module, and If I create module_name.inc I always put it into the includes directory. So for me module_load_include() is a unusable function, or at least hard to write and read when I use it..
I will probably switch to ctools_include if something like this does not get into D8.
Comments
Comment #1
larowlanAgree wholeheartedly. Many of my larger modules have their own wrapper to module_load_include because it is back to front.
Comment #2
pasqualleactually the
modules/search/search.pages.inc can be written as
which could be something "usable", but it is not how the api page describes it
http://api.drupal.org/api/drupal/includes--module.inc/function/module_lo...
see the node.admin.inc example
Comment #3
traviscarden commentedc.f. #697946: Properly deprecate module_load_include() and move it into \Drupal::moduleHandler() service
Comment #4
swentel commentedYeah this is really a duplicate
Comment #4.0
pasquallefix code example