Sunday, April 1, 2012

Creating modules in drupal7.x

Module  Name

The first step in creating a module is to choose a "short name" for it. This short name will be used in all file and function names in your module, so it must start with a letter, and it must contain only lower-case letters and underscores. For this example, we'll choose "current_posts" as the short name.

Create a folder and a module file

Given that our choice of short name is "current_posts" :
  1. Start the module by creating a folder in your Drupal installation at the path:
    • sites/all/modules/current_posts
  2. Create the PHP file for the module :
    • Save it as current_posts.module in the directory sites/all/modules/current_posts
    • As of Drupal 6.x, sites/all/modules is the preferred place for non-core modules (and sites/all/themes for non-core themes), because this places all site-specific files in the sites directory. This allows you to more easily update the core files and modules without erasing your customizations. Alternatively, if you have a multi-site Drupal installation and this module is for only one specific site, you can put it in sites/your-site-folder/modules.
  3. Add an opening PHP tag to the module :
    • <?php
    • Module files begin with the opening PHP tag. Do not place the CVS ID tag in your module. It is no longer needed with drupal.org's conversion to Git. If the coder module gives you error messages about it, then that module has not yet been updated to drupal.org's Git conventions.
  

No comments:

Post a Comment