Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
API page: https://api.drupal.org/api/drupal/includes%21module.inc/function/module_...
It seems the module_load_include() funcction can also be used to include files in the DRUPAL_ROOT/includes directory. However, this usage is not documented in the function comments.
// Load locale.inc from the DRUPAL_ROOT/includes directory.
module_load_include('inc', NULL, 'includes/locale');
Comment | File | Size | Author |
---|---|---|---|
#11 | 2827184-11.patch | 594 bytes | gaurav.kapoor |
Comments
Comment #2
jigariusComment #3
jigariusComment #5
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #6
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #7
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedRe-rolled since last one failed to apply.
Comment #9
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #11
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #12
tatarbjSeems a good idea to include the reporter's comment in code.
I'm putting it to RTBC because as i've seen it works well and can be merged.
Comment #13
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedGiven that the function has the word "module" in its name, and especially given that it contains the following code:
It seems pretty clear to me that a NULL $module only works by accident, no? I don't think it's an intended use of this function.
Comment #14
jigariusThat makes sense, David. However I've had many people sa me "How do I load a .inc file which lives in the includes directory?" If not with a NULL, what is the Drupal way of loading those?
Comment #15
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedUsually Drupal loads files from the includes directory via a direct require, like this:
With module-provided files, the module_load_include() API exists because a module can be installed at a variety of different places within the site's directory structure, and the API allows the calling code to not have to know where the file is located in order to include it.
But the core includes directory always exists in the same place... so files can just be directly loaded from it.