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');

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

breft created an issue. See original summary.

jigarius’s picture

Issue summary: View changes
jigarius’s picture

Status: Active » Needs review
FileSize
905 bytes

Status: Needs review » Needs work

The last submitted patch, 3: 2827184-improve-documentation.patch, failed testing.

gaurav.kapoor’s picture

Status: Needs work » Needs review
gaurav.kapoor’s picture

gaurav.kapoor’s picture

Re-rolled since last one failed to apply.

Status: Needs review » Needs work

The last submitted patch, 6: 2827184-6.patch, failed testing.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
614 bytes

Status: Needs review » Needs work

The last submitted patch, 9: 2827184-9.patch, failed testing.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
594 bytes
tatarbj’s picture

Status: Needs review » Reviewed & tested by the community

Seems 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.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

Given that the function has the word "module" in its name, and especially given that it contains the following code:

   $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";

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.

jigarius’s picture

That 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?

David_Rothstein’s picture

Usually Drupal loads files from the includes directory via a direct require, like this:

    require_once DRUPAL_ROOT . '/includes/common.inc';

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.