Syndicate

Feed

A brick came into the mail yesterday

I received in the mail my pre-ordered copy of Pro Drupal Development Second Edition yesterday.

The book is a brick. 667 pages with the index.

I am a little disappointed already... To be fair, I had high expectations. The treatment JavaScript and Ajax would receive was the first thing I'd look into.

AHAH is covered but the example provided is lame. It does not cover modifications to a form... Well it does, but you only inject some text in a field of type markup, so you do not need to fiddle with the cached form, or even read anything from it in the callback function. (The callback function is the PHP function that 'writes' the JSON that's returned to the browser...).

The chapter on jQuery provides one additional example module, besides PlusOne. That other module only attaches an additional JavaScript file to the page, using HOOK_init() and a registered theme function. No Ajax.

PlusOne still doesn't does degrade in this Drupal 6 version (see comments below). The book Learning Drupal 6 Module Development provides an example that does degrade. Meaning: without JavaScript, things won't look broken, as they do with the PlusOne module.

The chapter on jQuery explains how to add a function to Drupal.behaviors, but it does not explain how to pass a variable from Drupal PHP to the client-side Drupal.settings namespace. Learning Drupal 6 Module Development does explain this. It becomes important to use drupal_add_js to pass PHP variables over to our JavaScript to always avoid hard-coding certain values in our scripts.

We learned that in Drupal 6 our JavaScript is themable. Example, please? The book provides none.
(Any module's JavaScript file that produces HTML content must now provide default theme functions in the Drupal.theme.prototype namespace.)

The book does not even show one case where Drupal.t() is used. That function should have been mentioned at least.

Coverage of JavaScript best coding practices (such as... use camelCase for 'variable' and function names, etc.) should have found its place somewhere in that second edition, because the Drupal community and this very book are pushing hard for coding standards.

The book Learning Drupal 6 Module Development has its own shortcomings in its treatment of JavaScript due to the timing of its publication probably. By the way, the author of Learning Drupal 6 Module Development, Matt Butcher, has encouraged Drupal.org to update its handbook JavaScript coding standards page, to extend it based on a more thorough definition. Kuddos to him. JavaScript and Ajax are that important. Contributed modules developer (I am part of them) need to follow some conventions.

Last edited by Caroline Schnapp about 1 week ago.

Comments

Do you have the previous edition?

If so, would it be worth buying the new one?

I have the previous edition and it has proved exceedingly useful.

Also, I really rather like what you've done with the Garland theme. All the little tweaks really round it off especially the feed icon/mug.

Yes I do

I have the previous edition, and it was extremely useful to me as well. I read it from cover to cover.

I have only skimmed this new revision. From what I see here, and although this may be premature of me to say so, I still believe that it's worth getting for someone who has the older edition.

For someone who never read the first edition, then, by all means, do get this book, but you may be interested in also getting your hands on the Other book, by Matt Butcher. If you get both books, read Matt Butcher's book first. The style is much more engaging, and Matt Butcher is thorough, and is a fantastic writer. The style of the other book allows you to learn module development in one long week-end, and none of the examples in the book are contrived.

Thanks

Hi, Caroline. Thanks for your comments. You're the first person I've heard of to receive the 2nd edition.

I wish I had had you as an additional reviewer for the jQuery chapter!

I do think that the Plusone module degrades well. For me, the only difference is that with JavaScript off there is a full page submit instead of AJAX.

Best regards,

John

You're right

I do think that the Plusone module degrades well. For me, the only difference is that with JavaScript off there is a full page submit instead of AJAX.

Oh yeah! My mistake.

The code is different from its earlier Drupal 5 version. I had missed a snippet of code added to it.

There is only one callback function, still, except that it has a different behavior when JavaScript is disabled.

On page 399:

// Check to see if jQuery made the call. The AJAX
// call used the POST method and passed in the key/value pair js = 1.
  if (!empty($_POST['js'])) {
    // This will return results to jQuery's request.
    drupal_json(array(
      'total_votes' => $total_votes,
      'voted' => t('You voted')
      )
    );
    exit();
  }
 
  // It was a non-JavaScript call. Redisplay the entire page
  // with the updated vote total by redirecting to node/$nid
  // (or any URL alias that has been set for node/$nid).
  $path = drupal_get_path_alias('node/'. $nid);
  drupal_goto($path);

Congratulation, and sorry for biting your head off over that one, this is a major improvement over the First Edition.

To get the redirect $path, though, a simple call to url() will provide the alias if there's one. url() or l() — to get the anchor element, are Drupal developers' best friends. See this page: http://api.drupal.org/api/function/url/6.

  $path = url('node/'. $nid);
  drupal_goto($path);

Yes, I got the book rather quickly. Even Chapters Indigo (that sent the book to me, by normal slow mail), marks it as "pre-order" item, still.

I am lucky :-) I was impatiently waiting for it, that's why.

Does the second edition have

Does the second edition have any info on working with Simpletest? I'd love to see more info on that in book form.

Nothing on SimpleTest, no

There is no entry in the index under SimpleTest.

Under Testing and developing code, there is something, but the pages you are referred to show you how to use the Devel module.

Providing 2 callback functions...

The module PlusOne could, alternatively, provide two menu paths mapped to their individual callback function. There would be one callback function for the JSON 'service' and an other for the non-ajaxified JavaScript-disabled-in-the-browser route.

The JavaScript function executed when the DOM is ready could 'bind' a click event-handler to the vote link, an event-handler that would call the JSON service, reading the JSON URL from Drupal.settings.plusone.jsonUrl, for example — provided we set this property on the Drupal JavaScript object using the drupal_add_js function like so:

$path = url('plusone/json/vote/". $nid');
drupal_add_js(array('plusone' => array('jsonUrl' =>$path)), 'settings'):

There is one limitation to this: there ought to be only one voting widget on the page... as it stands now, the module only shows the widget on the page view so we're fine.

We would then avoid reading from the $_POST array to guess whether JavaScript is enabled or not.

Something else I find a little strange

There is no wildcard used for the node id in the path.

HOOK_menu is defined like so:

/**
 * Implementation of hook_menu().
 */
function plusone_menu() {
  $items['plusone/vote'] = array(
    'page callback' => 'plusone_vote',
    'access arguments' => array('rate content'),
    'type'  => MENU_CALLBACK,
  );
  return $items;
}

While the callback function does take a node id as parameter...

function plusone_vote($nid) {
  global $user;
  $nid = (int) $nid;
  ...

I would have used this HOOK_menu implementation instead:

/**
 * Implementation of hook_menu().
 */
function plusone_menu() {
  $items['plusone/vote/%'] = array(
    'page callback' => 'plusone_vote',
    'page arguments' => array(2);
    'access arguments' => array('rate content'),
    'type'  => MENU_CALLBACK,
  );
  return $items;
}

Both ways are perfectly valid

On page 65 of Chapter 4, The Menu System, we read this:

Any additional parts of the path are automatically passed along. [...] Defining page arguments is useful because you can call the same callback from different menu items and provide some hidden context.

I guess the author meant "not defining page arguments" in the HOOK_menu implementation... can be useful.

What percent of the book is new?

The book has a new co-author. I'm wondering if there are perhaps a couple of new chapters that were written by Dries. Hope his name isn't on it just to sex it up.

Dries only wrote the preface

Actually the book has one less author. Matt Westgate is not authoring the Second Edition — although... the Second Edition still reads like the First Edition with updates whenever applicable, so you could say that Westgate is still behind the Second Edition.

Dries still wrote a preface for this book, as he had for the First Edition.

There is obviously new content, as Drupal 6 has new features.

Right off the bat, I see two new chapters:

Chapter 3: Hooks, Actions and Triggers.
Chapter 23: Installation profiles.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <css> <html> <javascript> <mysql> <php> <span> <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <sup> <sub> <dd> <del> <blockquote> <img> <q> <p> <div>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <javascript>, <mysql>, <php>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 11 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.