5

I start to learning moding Drupal and I have a look for the current ones. There are files like [modulename].pages.inc or [modulename].api.inc and I can't find why it exists? I read that base files are only [modulename].module, [modulename].info, [modulename].install in Drupal book.

Can somebody explain me these files or post names all this kind files?

7

It's just a convention used for separating logic out of the main .module file.

The [modulename].pages.inc file typically contains page callback functions (those defined in hook_menu()). Since these functions aren't used in every page request there's no point including them, so they're auto-included from the file property defined in hook_menu() when needed.

You'll probably come across [modulename].admin.inc too, which typically contains callback functions for admin pages.

[modulename].api.php is another convention that Drupal core uses (and subsequently a lot of contrib modules use) to show examples of the hooks they provide, and usually how to use them.

There are other [modulename].[group].inc files that can be auto-included when another module implements hook_hook_info():

Normally hooks do not need to be explicitly defined. However, by declaring a hook explicitly, a module may define a "group" for it. Modules that implement a hook may then place their implementation in either $module.module or in $module.$group.inc. If the hook is located in $module.$group.inc, then that file will be automatically loaded when needed. In general, hooks that are rarely invoked and/or are very large should be placed in a separate include file, while hooks that are very short or very frequently called should be left in the main module file so that they are always available.

1
  • 4
    Doing this can help with the memory footprint, as files are only loaded if they are actually needed for a particular request.
    – mpdonadio
    Jul 7 '13 at 15:49

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.