Errata (Second Edition)

This page lists the errors found in the book. Help us improve this book by logging in and submitting any errors you find. In cases where errors exist in the code, they are corrected immediately in the code repository.

Chapter 2. Writing a Module, Page 18

Location on the page: 
two thirds down
Chapter: 
2. Writing a Module
Error: 

variable_get('annotate_node_types', array('story'))

Correction: 

variable_get('annotate_node_types', array('page'))

Description of the Error: 

Default value shown is not consistent with the module's (see last line on page 19).

Chapter 2. Writing a Module, Page 19

Location on the page: 
3rd paragraph
Chapter: 
2. Writing a Module
Error: 

Administer > Settings > Annotate

Correction: 

Administer > Site Configuration > Annotate

Description of the Error: 

Menu label is incorrect.

Chapter 2. Writing a Module, Page 19

Location on the page: 
last line
Chapter: 
2. Writing a Module
Error: 

'annotate_nodetypes'

Correction: 

'annotate_node_types'

Description of the Error: 

Variable is given a different name than in previous and following examples.

Chapter 2. Writing a Module, Page 23

Location on the page: 
Second code example, second function - annotate_uninstall()
Chapter: 
2. Writing a Module
Error: 

variable_delete('annotate_node_types');

Correction: 

variable_del('annotate_node_types');

Description of the Error: 

Function name is incorrect.

Chapter 2. Writing a Module, Page 23

Location on the page: 
Top of page
Chapter: 
2. Writing a Module
Error: 

CREATE TABLE annotate (
uid int(10) NOT NULL,
nid int(10) NOT NULL,
note longtext NOT NULL,
when int(11) NOT NULL default '0',
PRIMARY KEY (uid, nid),
);

Correction: 

CREATE TABLE annotations (
uid int(11) NOT NULL,
nid int(11) NOT NULL,
note longtext NOT NULL,
created int(11) NOT NULL default 0,
PRIMARY KEY (uid, nid)
)

Description of the Error: 

I know that the SQL is "something like" - but - having pasted it in and used schema module to cut'n'paste the code it would be better if it actually was valid SQL and matched the schema that was used.

There are two points that don't match

1) table name ("annotate" vs. "annotations")
2) column "when" is really column "created" (and "when" is a MySQL reserved word so would need quoting)

Plus - one error (at least for MySQL) - an extra comma after the PRIMARY KEY column.

Chapter 2. Writing a Module, Page 23

Location on the page: 
two thirds down
Chapter: 
2. Writing a Module
Error: 

In the downloadable code, hook_install() is missing the line to delete the module's variable.

Correction: 

Update online code to include:
variable_del('annotate_node_types')

Description of the Error: 

Omission from online code.

Chapter 2. Writing a Module, Page 30

Location on the page: 
n/a
Chapter: 
2. Writing a Module
Error: 

After creating new variables ('annotate_limit_per_node' and 'annotate_deletion') the .install file should be updated to delete those variables on uninstall.

Correction: 

Either instructions on what to add to annotate.install or just a brief note to remind the reader to do so would be helpful.

Chapter 3. Hooks, Actions, and Triggers, Page 36

Location on the page: 
4th chunk of example code at bottom of page
Chapter: 
3. Hooks, Actions, and Triggers
Error: 

function hook_nodeapi(&$node, $op, $a3=NULL, $a4=NULL) {

Correction: 

function beep_nodeapi(&$node, $op, $a3=NULL, $a4=NULL) {

Description of the Error: 

The function name should be "beep_nodeapi" rather than "hook_nodeapi". The hook itself is named hook_nodeapi(). The hooked version for the module needs to be name [module name]_nodeapi().

Chapter 3. Hooks, Actions, and Triggers, Page 41

Location on the page: 
2nd paragraph
Chapter: 
3. Hooks, Actions, and Triggers
Error: 

If you've done everything correctly, your action should be available

Correction: 

If you've done everything correctly and enabled the Beep module, your action should be available

Description of the Error: 

Minor suggestion: a reminder to enable the Beep module would be helpful.

Chapter 3. Hooks, Actions, and Triggers, Page 48

Location on the page: 
bottom
Chapter: 
3. Hooks, Actions, and Triggers
Error: 

array_merge($info['user_block_user_action']['hooks']['comment'], array('insert'));

Correction: 

array_unique(array_merge($info['user_block_user_action']['hooks']['comment'], array('insert')));

Description of the Error: 

array_merge() appends values instead of combining them when keys are numeric, as they are implicitly in the above array.