Errata (Second Edition)

This page lists the errors found in the book.

Chapter 4. The Menu System, Page 72

Location on the page: 
end of the page
Chapter: 
4. The Menu System
Error: 

function menufun_hello() {
return t('Hello');
}

function menufun_title() {
drupal_set_title(t('The page title'));
$now = format_date(time());
return t('It is now @time', array('@time' => $now));
}

Correction: 

function menufun_hello() {
drupal_set_title(t('The page title'));
return t('Hello');
}

function menufun_title() {
$now = format_date(time());
return t('It is now @time', array('@time' => $now));
}

Description of the Error: 

Drupal_set_title() have to be called in the page callback function and not in the title callback function.
If you call drupal_set_title() in the title callback function, the string past as paramater in the drupal_set_title() override every title on your site.

Chapter 4. The Menu System, Page 74

Location on the page: 
Between first paragraph and the figure
Chapter: 
4. The Menu System
Error: 

There is no error, but the text could be clearer about how things work.

Correction: 

It is important to realize that the arguments passed to the title callback function are completely different depending on whether the callback function is t() or some other function.

In the case of t(), the first argument will be the value set for the menu's title key, and the second argument will be the array of arguments assigned to the menu's title arguments key.

However, if the callback is any other function, it will not receive the value set for the menu's title key, nor will it receive the array of title arguments. Instead, it will receive the values in the array of title arguments, with each value being passed in as its own argument. So, the value of the first item in the title arguments array will be passed in as the first argument to the callback function, etc.

Example:

$items['menutoy/bye'] = array(
  'title' => 'bye bye @name',
  'title callback' => 'menutoy_title',
  'title arguments' => array('@name' => 'foo'),
  'access callback' => true,
);

The menutoy_title() function will receive 'foo' as its first and only argument.

On the other hand, if the title callback function is t(), its first argument will be 'bye bye @name', and its second argument will be array('@name' => 'foo').

Thus if one wishes to have the value of the title passed to one's custom title callback function, one will have to make sure to include it as one of the values in the title arguments array.

Chapter 4. The Menu System, Page 75

Location on the page: 
Code block.
Chapter: 
4. The Menu System
Error: 


function menufun_menu() {
  $items['menufun/%'] = array(
    'title' => 'Hi',
    'page callback' => 'menufun_hello',
    'access callback' => TRUE,
  );

  return $items;
}

Correction: 


function menufun_menu() {
  $items['menufun/%'] = array(
    'title' => 'Hi',
    'page callback' => 'menufun_hello',
    'page arguments' => array(1),
    'access callback' => TRUE,
  );

  return $items;
}

Description of the Error: 

The $items['menufun/%'] array does not include the page arguments key/value pair, which fires a missing argument error when accessing the page.

Chapter 4. The Menu System, Page 82

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

/**
* Implemantation of hook_link_alter().
*...
**/

Correction: 

/**
* Implemantation of hook_menu_link_alter().
*...
**/

Description of the Error: 

hook_link_alter() and hook_menu_link_alter() are two differents hooks. Not annoying because it's in the comment's code, but can mislead the user.

Chapter 5. Working with Databases, Page 92

Location on the page: 
Last line
Chapter: 
5. Working with Databases
Error: 

SELECT FROM role WHERE rid > 1 and rid != 7

Correction: 

SELECT name FROM role WHERE rid > 1 and rid != 7

Description of the Error: 

The example does not include the table name in the query. The database will execute the query on the table 'name'.

Chapter 5. Working with Databases, Page 94

Location on the page: 
3rd Code Sample
Chapter: 
5. Working with Databases
Error: 


$result = db_query_range(db_rewrite_sql($sql), $type, $status, 0, 10);

Correction: 


$result = db_query_range(db_rewrite_sql($sql), 0, 10, NULL, $type, $status);

Description of the Error: 

According to api.d.o, pager_query receives SQL arguments from the fifth parameter on.

Chapter 5. Working with Databases, Page 95

Location on the page: 
2nd paragraph
Chapter: 
5. Working with Databases
Error: 

Note that you pass the variables that will fill placeholders before the range (so the type
and status are passed before 0 and 10 in the example just shown).

Correction: 

Note that you pass the variables that will fill placeholders after the range and an optional count query (so the type and status are passed after 0, 10 and an undefined string in the example just shown).

Description of the Error: 

According to api.d.o, pager_query receives SQL arguments from the fifth parameter on.

Chapter 6. Working with Users, Page 123

Location on the page: 
top of the page
Chapter: 
6. Working with Users
Error: 

case 'insert':
// Record information for future lawsuit.
watchdog('user', t('User %user agreed to legal terms',
array('%user' => $user->name)));
break;

Correction: 

case 'insert':
// Record information for future lawsuit.
$name = $edit['name'];
watchdog('user', t('User %user agreed to legal terms',
array('%user' => $name)));
break;

Description of the Error: 

when operation insert happen, the user object is still loaded as anonymous, so $user->name get any information.
To get the new user's name you have to use the $edit variable who content the value submit by the new user in a array. So to get the name you have to use $edit['name'].

Chapter 6. Working with Users, Page 126

Location on the page: 
2nd and 3rd paragraph
Chapter: 
6. Working with Users
Error: 

"First up is sites/all/modules/custom/loginhistory.info"
and
"...so we create sites/all/modules/custom/loginhistory.install"

Correction: 

"First up is sites/all/modules/custom/loginhistory/loginhistory.info"
and
"...so we create sites/all/modules/custom/loginhistory/loginhistory.install"

Description of the Error: 

The loginhistory.info and loginhistory.install files should be placed inside the newly created 'loginhistory' folder.

Chapter 6. Working with Users, Page 127

Location on the page: 
near end of listing 6-4
Chapter: 
6. Working with Users
Error: 

Schema for login history lists a single index for the table as:

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

Correction: 

Since we are maintaining a history of multiple logins for each user, 'uid' cannot be a primary or unique key. A general index is designated:

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

Description of the Error: 

Drupal Schema API syntax error.