Errata (Second Edition)

This page lists the errors found in the book.

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 18

Location on the page: 
last paragraph, last sentence
Chapter: 
2. Writing a Module
Error: 

We're going to allow annotation of story node types by default

Correction: 

We're going to allow annotation of page node types by default

Description of the Error: 

The code example on p 17 and the screenshot on p 19 show 'page' as the default; the one-line code example should reference 'page' too instead of 'story'.

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 20

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

if (!in_array($node->type, $types_to_annotate)) {

Correction: 

if (!in_array($node->type, $types_to_annotate, TRUE)) {

Description of the Error: 

Also on page 26, middle of page.

Strict mode for in_array() must be used or the if will fail and thus the annotation form would be displayed on nodes of all types, not just the types selected in Home / Administer / Node annotation. [Fixed in downloadable code.]

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.

[Fixed in downloadable code. -JV]

Chapter 2. Writing a Module, Page 25

Location on the page: 
First paragraph right after the tip.
Chapter: 
2. Writing a Module
Error: 

In the paragraph that comes before the code on handling submission of the annotation form, it's not said which file in the annotate module folder to put the code in.

Correction: 

The code that follows that paragraph goes in the annotate.module file.

Description of the Error: 

The file that you work on before going into the handling of submission of the annotation form is the annotate.install file. It's not said whether or not this code is supposed to go in the annotate.install file or not.

Chapter 2. Writing a Module, Page 28

Location on the page: 
Paragraph after Figure 2-3
Chapter: 
2. Writing a Module
Error: 

If you're following along at home, you’ll need to clear the menu cache to see the link
appear. You can do this by truncating the cache_menu table...

Correction: 

If you're following along at home, you’ll need to rebuild the menu router table to see the link
appear. You can do this by visiting admin/build/modules...

Description of the Error: 

In Drupal 6, clearing the menu cache is no longer enough. You must rebuild the menu_router table to get new menu entries to appear. The menu_router table is rebuilt automatically when you visit admin/build/modules, or use the devel module to rebuild it.