5

I suppose there's a drupal page somewhere that explains this, but I can't find it.

When creating a module, you can have files that end with .module, .info, .inc, etc...

What are all the file extensions that are recognized and what do they do?

0

3 Answers 3

8

The extensions that are specific for Drupal, or that have a specific meaning in Drupal, are the following ones:

  • The .api.php extension is used for the file describing the hooks used by a module, such as system.api.php.
  • The .install extension is used for the file that is used when a module is installed, such as system.install. It is also loaded when Drupal is verifying the requirements needed from a module.
  • The .inc extension is used for any secondary file that contains code that is loaded only when necessary. If the code is used in specific cases, such as when a specific menu callback is being invoked, then the code is moved in a separated .inc file. Often, you will find modules using a file with the .admin.inc extension (e.g. node.admin.inc) that includes all the code necessary to run the administrative interface, and a file with .pages.inc extension (e.g. node.pages.inc) that contains the code executed for other menu callbacks. If a module implements tokens, in Drupal 7 you will find files using .tokens.inc as extension (e.g. user.token.inc); those are the files where the implementations of hook_token_info(), and hook_tokens() are looked for (see system_hook_info()).
  • The .info extension is used for the file describing the module, or the theme, such as system.info. It contains metadata, such as the required Drupal version, the minimum PHP version with which the module/theme is compatible, and other information specific for the module, or the theme.
  • The .module extension is used for the main file of a module, such as system.module.
  • The .test extension is used for the files containing the testing code (e.g. system.test), which is actually running on the SimpleTest framework.
  • The .theme extension was used from themes not using PHPTemplate template engine. In Drupal 6 (and before) the extension was used from the chameleon.theme file; in Drupal 7, there aren't themes using that extension.
  • The .tpl.php extension is used for the template files used from theme functions, such as node.tpl.php.

Third-party modules can use specific extensions, such as the following ones:

  • The .views_default.inc extension is used for files (e.g. node.views_default.inc) containing the code to implement the default views used from a module that integrates with the Views module.
  • The .views_template.inc extension is used for files (e.g. node.views_template.inc) containing the code for views templates.
  • The .rules.inc extension is used for files containing code for integrating with the Rule module.
0
5

A quick googling of 'writing drupal modules' returned the following developer guides:

There is also a project, Examples for Developers, which gives lots of insight into module writing and best practices, etc. It has versions for multiple releases of Drupal as well.

With more respect to .inc files, the documentation for module_load_include() explains how Drupal includes them within modules. Basically they are the Drupal's way of breaking up modules into more manageable pieces. Otherwise, a complex module might have a gigantic .module file.

Also, sometimes modules don't need all of their code loaded; so, code that is only called in certain routines is delegated to a .inc file for performance reasons and loaded only when needed.

If screencasts are more helpful, you might want to check out Your First Module - A Mostly Painless Intro to Drupal Development and click on the screencast link.

Bob over at http://mustardseedmedia.com/podcast has some great podcasts as well; most of his are D6, but he is getting more and more into D7.

5
  • I don't really see a breakdown on either of those pages. Like where does it talk about .inc files?
    – kylex
    Commented Apr 23, 2012 at 21:33
  • 1
    .inc files are php include files, and are not specific to drupal, but to any php environment. a quick grep through any of the .module files will show you what's going on, as will the opening <?php tag. But these links will show you all the drupal specific files like .module, .info, .install, etc.
    – Jimajamma
    Commented Apr 23, 2012 at 21:39
  • 1
    You should really summarize this as just providing links aren't considered good answers on DA or any other SE sites.
    – mpdonadio
    Commented Apr 23, 2012 at 21:44
  • @kylex I think yo are here for some a,b,c ... Tutorial !
    – niksmac
    Commented Apr 24, 2012 at 7:35
  • The question is about the extensions normally used in Drupal; the first link is for a page describing how to write a Drupal module, but it doesn't report the extensions normally used from Drupal.
    – avpaderno
    Commented Apr 24, 2012 at 8:05
2

A module conatins mainly 3 imp files

  1. List item- .info file -> a file which contains d module information like name version etc.
  2. List item- .module file -> a file that describes how a module works.
  3. List item- .install file -> this file is run for first time when the module is configured.this is maily to create database tables and the corresponding fields,this file has to be updated if we make any version change in module.

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.