I'd like to execute PHP code that requires functions available in the includes files of core located in core/includes.

I found ModuleHandler()->loadInclude() and module_load_include() but I am afraid this 2 options can load files from core/modules directory only, according to the doc, but may be I misinterpreted it:

Loads a module include file.

For example if I execute:

\Drupal::moduleHandler()->loadInclude('core', 'inc', 'install');
drupal_rewrite_settings(); // the func that I want located in install.inc

I get:

Call to undefined function drupal_rewrite_settings()

which means install.inc has not been loaded.


You can use a good old fashioned include_once (or require_once):

include_once DRUPAL_ROOT . '/core/includes/install.inc';

Core uses the same method any time it needs to source a file in core/includes. Case in point, ModuleHandler::loadInclude itself does exactly that if the file extension provided is "install":

public function loadInclude($module, $type, $name = NULL) {
  if ($type == 'install') {
    // Make sure the installation API is available
    include_once $this->root . '/core/includes/install.inc';

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.