I have created custom module in Drupal 7.

I want to create one file and in this file I want to create all functions that I need to use in this module. I want to call these functions in .module file. So for this what file and how can I use these functions?


It's PHP, so you use require or include to include functions from other files.

Drupal's wrapper around those is module_load_include. Examples from the docs:

// Load node.admin.inc from the node module.
module_load_include('inc', 'node', 'node.admin');
// Load content_types.inc from the node module.
module_load_include('inc', 'node', 'content_types');

Only use this function inside another function, not in global scope. If you need to unconditionally depend on a separate file for a whole module, just use require_once or whatever makes most sense for your use case.

  • I am creating custom module and want to use all function in .module file . and I have one file in module where I created all functioans. – jsh May 14 '16 at 11:08
  • I know, that's what your question says. This is the answer to that question – Clive May 14 '16 at 11:09

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.