06.05.2013 Views

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

*/<br />

function jsloader_init() {<br />

$path = drupal_get_path('module', 'jsloader');<br />

$info = drupal_parse_info_file($path . '/jsloader.info');<br />

foreach ($info['scripts'] as $script) {<br />

drupal_add_js($path . '/' . $script);<br />

}<br />

}<br />

Taking a quick look at this file. We can see the following:<br />

• It begins with a tag. Why? For library files such as this, the closing tag is optional <strong>and</strong><br />

can actually lead to application-breaking mistakes. <strong>Drupal</strong> conventions<br />

re<strong>com</strong>mend omitting the closing tag for this reason.<br />

[ 249 ]<br />

Chapter 8<br />

In Chapter 2, we discussed coding st<strong>and</strong>ards, which included spacing, <strong>com</strong>menting,<br />

<strong>and</strong> the general structure of code. We will not repeat that discussion, but there are<br />

two things to note about the way PHP code is generally structured in <strong>Drupal</strong>.<br />

First, most <strong>Drupal</strong> PHP code is procedural, not object-oriented. Functions are defined<br />

in the global namespace <strong>and</strong> are not usually assigned to objects. This will change in<br />

<strong>Drupal</strong> 7, which will be object-oriented to a greater extent.<br />

Second, function names <strong>and</strong> variable names are always lowercase, with words<br />

separated by underscores. Camel case (myVariable) is never used in <strong>Drupal</strong>'s<br />

procedural code.<br />

With these few notes addressed, we are ready to look at the first function,<br />

jsloader_help().<br />

The jsloader_help() function<br />

The purpose of this first function, jsloader_help(), is to provide some content for<br />

the <strong>Drupal</strong> built-in help system. Always provide a help function for your module,<br />

even if it does no more than provide basic information about what the module does.<br />

A little help is better than no help.<br />

This material is copyright <strong>and</strong> is licensed for the sole use by Richard Ostheimer on 18th June 2009<br />

2205 hilda ave., , missoula, , 59801

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

Saved successfully!

Ooh no, something went wrong!