Errata (Third Edition)

This page lists the errors found in the book.

14

Location on the page: 
First set of code
Chapter: 
2. Writing a Module
Error: 

configure=admin/config/content/annotate/settings

Correction: 

configure=admin/config/annotate/settings

Description of the Error: 

Links to the wrong page.

14

Location on the page: 
Last sentence
Chapter: 
2. Writing a Module
Error: 

Last sentence of page 14 says "Begin the file with an opening PHP tag and a CVS identification tag, followed by a comment".

Correction: 

Should be ''Begin the file with an opening PHP tag, followed by a comment"

Description of the Error: 

Last sentence on page 14 says 'Begin the file with an opening PHP tag and a CVS identification tag, followed by a comment' . However, the relevant code on page 15 (top code section) does not have the CVS tag. In the second edition, we have the CVS tag $Id$.

As Drupal moved away from CVS, I believe the code segment is correct, but the sentence is wrong. Not the other way round.

18

Location on the page: 
second to last line of the code at the top of the page
Chapter: 
2. Writing a Module
Error: 

return system_settings_form($form);

Correction: 

return system_settings_form($form, TRUE);

Description of the Error: 

missing argument

20

Location on the page: 
In the code, near the top
Chapter: 
2. Writing a Module
Error: 

field_delete_instance($instance);

Correction: 

field_delete_instance($instance, false);

Description of the Error: 

If the function field_delete_instance() is called without the second parameter being set to false, the annotation field (table) is deleted when 0 content types are checked on the Annotations config page. Therefore, when you check 1 or more content types later, you get the following error message:

FieldException: Attempt to create an instance of a field annotation that doesn't exist or is currently inactive. in field_create_instance() (line 455 of /Users/Eric/Sites/Dev/ProD7Dev/modules/field/field.crud.inc).

Line 452 - 456 of field.crud.inc
function field_create_instance($instance) {
$field = field_read_field($instance['field_name']);
if (empty($field)) {
throw new FieldException(t("Attempt to create an instance of a field @field_name that doesn't exist or is currently inactive.", array('@field_name' => $instance['field_name'])));
}

Line 736 - 759 of field.crud.inc
function field_delete_instance($instance, $field_cleanup = TRUE) {
.
.
.
.
.
// Delete the field itself if we just deleted its last instance.
if ($field_cleanup && count($field['bundles']) == 0) {
field_delete_field($field['field_name']);
}
}

21

Location on the page: 
2nd paragraph down
Chapter: 
2. Writing a Module
Error: 

I will then use the node_get_types() API

Correction: 

I will then use the node_type_get_types() API

Description of the Error: 

The node_get_types() function is not available in Drupal 7

26

Location on the page: 
Last sentence of 1st paragraph
Chapter: 
2. Writing a Module
Error: 

The last sentence reads:
or by using the “Clear cached data” button

Correction: 

It should read:
or by using the “Clear all caches” button

Description of the Error: 

The button "Clear cached data" was changed to "Clear all caches" in Drupal 7.

34

Location on the page: 
3rd section of code on the page
Chapter: 
3. Hooks, Actions, and Triggers
Error: 

function beep_user(&$edit, $account) {

Correction: 

function beep_user_login(&$edit, $account) {

Description of the Error: 

Not a proper implementation of hook_user_login().

42

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

The screenshot in Figure 3.4 is of the wrong overlay. (What is shown in Figure 3.4 is not available until an instance of the advanced action has been created as described on pp. 43-44 and in Figure 3.5.)

Correction: 

What should be shown in Figure 3.4 is the overlay accessed by clicking the Configuration link in the top menu and then clicking on the Actions link in the Configuration page, and finally scrolling to the bottom of the overlay to the "Create an Advanced Action" drop-down select box.

42

Location on the page: 
The paragraph between the code segment and Figure 3.4
Chapter: 
3. Hooks, Actions, and Triggers
Error: 

Administer-> Site configuration-> Actions

Correction: 

Configuration->Actions

Description of the Error: 

The navigation instructions are slightly incorrect-- they appear to be for Drupal 6.

43

Location on the page: 
in validate function
Chapter: 
3. Hooks, Actions, and Triggers
Error: 

if (!is_int($beeps))

Correction: 

if (!is_numeric($beeps))

Description of the Error: 

the is_int function can't read the string stored through the form, use is_numeric instead

64

Location on the page: 
Figure 4-3 and onwards
Chapter: 
4. The Menu System
Error: 

The Greetings menu should not appear in the figures as this is a MENU_CALLBACK. The Greetings title also does not appear (at least in my Drupal it says "Home").

Please note that on page 68 MENU_CALLBACK is replaced by MENU_NORMAL_ITEM and from here onwards the menu item should appear.

67

Location on the page: 
First code sample
Chapter: 
4. The Menu System
Error: 

This code does not receive the URL arguments

Correction: 

To receive the URL arguments it should be something like:

function menufun_hello($first_name='', $last_name='', $first_arg='', $second_arg='') {
$replace = array(
'@first_name' => $first_name,
'@last_name' => $last_name,
'@first_arg' => $first_arg,
'@second_arg' => $second_arg,
);
return t('Hello @first_name @last_name from Menu Fun with arguments @first_arg, @second_arg', $replace);
}

74

Location on the page: 
1st code snippet
Chapter: 
4. The Menu System
Error: 

drupal_set_title overrides the page title on every page.

Correction: 

drupal_set_title should be in the page callback, not the title callback.

Description of the Error: 

I just moved the line that sets the title to menufun_hello and now it only overrides the title for that page.

76

Location on the page: 
Bottom Paragraph
Chapter: 
4. The Menu System
Error: 

"The second parameter, $b, is being passed ..." , but $b is never used or explained.

Correction: 

"A second parameter /bar/baz is passed ..."

77

Location on the page: 
Point 5
Chapter: 
Front Matter
Error: 

user_view() does not exist

Correction: 

Probably, it refers to user_view_page()

77

Location on the page: 
Point 1
Chapter: 
4. The Menu System
Error: 

"In this case the string would be user_uid_optional."

Correction: 

The text should read "In this case the string would be user_uid_only_optional."

Description of the Error: 

The text in point 1 does not agree with the $items array above.

79

Location on the page: 
%index section
Chapter: 
Front Matter
Error: 

%index is not explained anywhere

80

Location on the page: 
Upper code
Chapter: 
Front Matter
Error: 

The 'logout' menu path does not exist in Drupal 7

Correction: 

In Drupal 7 the right path is $items['user/logout']

80

Location on the page: 
upper chunk of code, function menufun_hello
Chapter: 
4. The Menu System
Error: 

the code
function menufun_hello($animal) {
return t(“Hello $animal”);
}

doesn't fetch the argument for the return() statement.

also the quotation marks used here cause errors on copy and paste.

Correction: 

function menufun_hello($animal) {
return t(
'Hello @animal!',
array(
'@animal' => $animal
)
);
}

Description of the Error: 

as seen on the bottom of page 64, the t() function requires @something and then an array stating that @something is the key and $something is the value.

81

Chapter: 
Front Matter
Error: 

The way to execute the logout hook is incorrect.

Correction: 

In Drupal 7 the logout hook is named hook_user_logout(). Therefore, the invocation should be module_invoke_all('user_logout', $user).

85

Location on the page: 
Code sample on Pages 85-86
Chapter: 
4. The Menu System
Error: 

The code example for "Displaying Menu Items as Tabs" results in multiple instances of the following error message:
Warning: Invalid argument supplied for foreach() in menu_unserialize()

Correction: 

Changing all instances of "access arguments" with "access callback" seems to fix it.

85

Location on the page: 
Code sample on pages 85-86
Chapter: 
4. The Menu System
Error: 

Milkshake menu is not displayed and the following warning appears:

Warning: Invalid argument supplied for foreach() in menu_unserialize()

Correction: 

Changing all instances of "access arguments" with "access callback", as suggested in previous errata, got rid of the error message(s) but the menu still did not appear. I downloaded the source zip from the Apress website and applied the corrections from the "missingSource/Chapter_04_source" folder and everything works fine now.

Change each of your 'access arguments' (not 'access callbacks'), as follows:

'access arguments' => array('list flavors'),

with the exception of 'milkshake/add', which should be changed to:

'access arguments' => array('add flavor'),

107

Location on the page: 
Table 5-1
Chapter: 
5. Working with Databases
Error: 

Several of the datatype sizes in the MySQL column (first column) are split making them difficult to read at first glance.

Correction: 

Remove the spaces in the type sizes.

128

Location on the page: 
The end of Listing 6-5 at the top of the page.
Chapter: 
6. Working with Users
Error: 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ')' in <Your Drupal 7.x install location>/sites/all/modules/custom/loginhistory/loginhistory.install on line 29

Correction: 

Single quote needs to be added to the 'uid' key in function loginhistory_schema().

'uid' => array('uid),

Insert single quote at end of 2nd uid:

'uid' => array('uid'),

133

Location on the page: 
The second line of the last code example starting db_query(...
Chapter: 
6. Working with Users
Error: 

$account->uid, 'module' => 'authdave');

Correction: 

$account->uid, ':module' => 'authdave');

Description of the Error: 

Added missing colon : in front of the array key value so the SQL will correctly substitute. Also, trivially, removed a space from each of the double spaces surrounding the quoted key value.