24

I am trying to figure out what the main difference is between mymodule.module and mymodule.admin.inc.

Can anybody explain it?

4 Answers 4

20

Without going into the ins and outs, Drupal understands the .module file as being a module within the system. The .inc notation has always been used in PHP for 'include' files. When developing modules you might want to split functionality into different .inc files.

Modules being used in specific cases use conventions similar to .admin.inc. That file typically includes all the code necessary to run the administrative interface, and a file node.pages.inc for example contains the code executed for other menu callbacks.

17

Adding on to the answer given by Alex Gill

  1. .module files are loaded on every load page, whereas .inc files are loaded only when they are requested.
  2. By convention .module files should contains only those functions which are implementation of hooks. Following this standard improves the performance too.
  3. .inc files can be included by mentioning the path in hook_menu(), or by making an explicit using module_load_include('inc', 'node', 'node.admin').
  4. If any of the .inc files contains class objects, it should be mentioned in the .info file of the module.
9

In short, mymodule.module is the php file that drupal automagically loads when that module is enabled. It can then include other files when needed. Usually, mymodule.admin.inc is included to create its admin settings menu. If you grep through mymodule.module, you can see where. Sometimes when a module gets pretty complex, it is broken up into smaller files and they are then included as well.

1
  • 2
    There are other files Drupal automatically loads, and those are not files with extension .module. Actually, Drupal automatically loads also .inc files; therefore, that cannot be used to differentiate .module, and .inc files.
    – avpaderno
    Commented Dec 24, 2012 at 11:42
1

Difference between module file and inc file

  • .module file can be loaded by drupal for every page load. function in the module file can be used in other module file with out including that module(* but need to enable and dependency need to be added).
  • .inc file can be loaded by manually. It need to contains specific page functions.

For example hook_node_load, hook_form_alter need to be in .module file.

2
  • that does not distinguish the two files, as both are loaded automatically on module enable. as for .inc hook_node_load can also be called from a .inc file
    – saadlulu
    Commented Dec 26, 2012 at 11:50
  • .inc file might have included in that related module file and for functionality separation can be done by .inc for user understand. Commented Dec 26, 2012 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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