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.

Creating Your First <strong>Module</strong><br />

Not in JavaScript!<br />

<strong>Drupal</strong> programmers make the mistake of using a similar syntax in<br />

<strong>Drupal</strong> JavaScript. Object literal definitions (the JavaScript equivalent of<br />

associative arrays) do not allow the last item to terminate with a comma.<br />

Doing so causes bugs in IE and other browsers.<br />

Now we have walked through our first module's code. For all practical purposes, we<br />

have written an entire module (though we still have some automated testing code to<br />

write). Let's see what this looks like in the browser.<br />

The first module in action<br />

Our module is written and ready to run. To test this out, we need to first enable the<br />

module, and then go to the block administration page.<br />

The module can be enabled through the <strong>Module</strong>s menu. Once it is enabled, go to<br />

Structure | Blocks. You should be able to find a block described as A listing of all of<br />

the enabled modules. (This text came from our first_block_info() declaration.)<br />

Once you have placed this module in one of the block regions, you should be able to<br />

see something like this:<br />

[ 48 ]

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

Saved successfully!

Ooh no, something went wrong!