Errata (First Edition)

This page lists the errors found in the first edition of the book.

Chapter 4. The Menu System, Page 44

Location on the page: 
Code example
Error: 

module_exist('devel')

Correction: 

module_exists('devel')

Description of the Error: 

typo: function name

Chapter 4. The Menu System, Page 44

Location on the page: 
Implementation of hook_menu()
Error: 

function mymodule_menu()

Correction: 

return $items;

Description of the Error: 

should the function return $items?

[Yes! The final line of mymodule_menu() was omitted, and should be return $items; -JV]

Chapter 4. The Menu System, Page 44

Location on the page: 
Section "Programmatically Modifying Existing Menus"
Error: 

This section implies that by using the !$may_cache case in hook_menu() in a custom module it is possible to arbitrarily overwrite existing menu item definitions.

However, while it is possible to do this using the $may_cache case and by increasing the custom module's weight in the system table so that it is called after the module originally providing the menu path, only certain elements of the menu item can be overwritten by using the !$may_cache trick.

For example, while the callback can be overwritten, the 'access' element cannot, hence the line:
'access' => user_access('access devel information')
is actually redundant.

See http://drupal.org/node/189384#comment-625981 et seq. for more info; this also references the relevant code in menu.inc.

Chapter 4. The Menu System, Page 44

Location on the page: 
code sample
Error: 

this line does not have an effect on the menu that is displayed as part of the devel menu:
'title' => t('Wrap cache clear'),

Correction: 

unknown

Description of the Error: 

The above code does not work; the text of the Empty cache link remains "Empty cache" instead of "Wrap cache clear". However, the callback function does work, giving me the updated status message when going to devel/cache/clear.

Chapter 4. The Menu System, Page 46

Location on the page: 
Top, code example
Error: 

'path' => 'admin/user/eradicate',

Correction: 

'path' => 'admin/user/user/eradicate',

Description of the Error: 

Incorrect path to menu item (Drupal 5.2)

Chapter 5. Working with Databases, Page 49

Location on the page: 
Second line from bottom.
Error: 

injections.This layert

Correction: 

injections. This layer

Description of the Error: 

Typo. Missing space and extra 't'.

Chapter 5. Working with Databases, Page 54

Location on the page: 
First line of Getting Results for Paged Display code listing
Error: 

n.created DESC"

Correction: 

n.created DESC";

Description of the Error: 

Typo.

Chapter 5. Working with Databases, Page 54

Location on the page: 
Getting Results for Paged Display
Error: 

The line reading...$result = pager_query(db_rewrite_sql($sql), 0, 10); ... is incorrect. According to the drupal API documentation, the second paramater to the pager query is the number of query results to display per page. This number is used in a division arithmatic operation somewhere in Drupal. When it is set to 0, a divide by zero error is return.

Correction: 

The default number of page results is 10, so simply stating...$result = pager_query(db_rewrite_sql($sql));... works just fine. If a user wanted 25 results per page he can have $result = pager_query(db_rewrite_sql($sql));

Description of the Error: 

Divide by Zero error

Chapter 5. Working with Databases, Page 55

Location on the page: 
Section "Exposing Queries to Other Modules with hook_db_rewrite_sql()"
Error: 

The initial paragraphs in this section confuse the core function db_rewrite_sql() with the hook hook_db_rewrite_sql() (which can be implemented in modules). This confusion is cleared up in Table 5-2, but it would be preferable if the confusion were not created in the first place!

For a start, the hook does not expose queries to other modules, so the title of the section is itself confusing.

Then the first paragraph starts by talking about the hook, but in the 2nd sentence changes tack and talks about the function.

On p. 56, in subsection "Wrapping Queries", the hook is described where the function should be described (actually the description would be the same, but the given "function signature" should be for the function, not the hook).

Correction: 

Change the section title to something like "Drupal's Query Rewriting Mechanism: db_rewrite_sql() and hook_db_rewrite_sql()".

Delete the first sentence of the first paragraph in this section.

After the short paragraph "If you are not ... in your module." add the following sentence: "This allows your module to modify queries created elsewhere in Drupal so that you do not have to hack modules directly."

Description of the Error: 

The text confuses the function db_rewrite_sql() with the hook hook_db_rewrite_sql().

Chapter 5. Working with Databases, Page 60

Location on the page: 
function book_update_1()
Error: 

last line of function is missing

Correction: 

return $items;

Description of the Error: 

Update functions in .install files must return the array they have built.