Saturday, May 9, 2015

How To Make A Drupal Module: Part 1

Creating a Drupal Module is easy! At the minimum, you only need two files; a .info file, which describes our module and a .module file, which is where most of our code goes.

First things first, you need to create a folder to place our two files in. Call it my_module and place it in sites/all/modules (I place mine in sites/all/modules/custom).


.info file

Only two parameters are required for this file: name and core. Name is the name of your module and core is the version of drupal your module will be compatible with. It's recommended to add a "description" parameter as that shows a nice little description in the module list. With the three parameters, your .info file should look like this:

name = My Module
description = my description
core = 7.x

For a list of all parameters, visit drupal's documentation on the .info file.

Assuming your module is called "My Module," you want to place that snippet in a file called my_module.info, the extension being .info.

.module file

The .module file is where the bulk of our coding will be employed. The name of the .module file follows the same nomenclature as the .info, so it will be called my_module.module, the extension being .module.

That's it! You now have a basic (very basic) module. To see it in the modules list, you must first flush your cache.

No comments:

Post a Comment