18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Now we have created our first.info file. As soon as <strong>Drupal</strong> reads this file, the<br />

module will appear on our <strong>Module</strong>s page.<br />

Chapter 2<br />

In the screenshot, notice that the module appears in the DRUPAL 7 DEVELOPMENT<br />

package, and has the NAME and DESCRIPTION as assigned in the .info file.<br />

With our .info file completed, we can now move on and code our .module file.<br />

<strong>Module</strong>s checked into <strong>Drupal</strong>'s version control system will<br />

automatically have a version directive added to the .info file.<br />

This should typically not be altered.<br />

Creating a module file<br />

The .module file is a PHP file that conventionally contains all of the major hook<br />

implementations for a module. We discussed hooks at a high level in the first<br />

chapter. Now we will gain some practical knowledge of them.<br />

A hook implementation is a function that follows a certain naming pattern in order<br />

to indicate to <strong>Drupal</strong> that it should be used as a callback for a particular event in the<br />

<strong>Drupal</strong> system. For Object-oriented programmers, it may be helpful to think of a<br />

hook as similar to the Observer design pattern.<br />

[ 33 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!