Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Learning Drupal 6 Module Development

samzenpus posted about 6 years ago | from the read-all-about-it dept.

Programming 39

Michael J. Ross writes "Of all the content management systems (CMSs) that a Web developer could use for creating a new site, the best ones allow the developer to extend the chosen CMS's capabilities, by adding new functionality, in the form of third-party modules. This is one of many reasons why Drupal is growing in popularity: Developers can choose from hundreds of Drupal modules but not all functionality that a developer might want has been captured in a module, and many of the modules are unfinished or otherwise limited in capabilities. Fortunately, PHP programmers can create their own modules, and one way to get up to speed is Learning Drupal 6 Module Development, authored by Matt Butcher."Published on 10 May 2008 by Packt Publishing, under the ISBNs 1847194443 and 978-1847194442, the book is intended as a tutorial for developing your first Drupal 6 module; yet it also explains how to create themes and custom content types, how to use external XML APIs, and how to add AJAX functionality to your Drupal site using jQuery.

The book spans 328 pages, grouped into nine chapters, each devoted to a major topic of Drupal module development: Drupal's architecture and primary concepts (nodes, users, blocks, menus, etc.); an introduction to building a new module; Drupal's theme system, and how to create a custom one; module theming; using JavaScript, AJAX, and JSON; creating a custom administration module; creating a new content type, using the CCK; filters, input formats, hooks, actions, and triggers; installation profiles, how to develop one, and how to package a distribution. Throughout the book, the author illustrates key ideas by applying them to a sample Web site, named the Philosopher Bios. The material assumes that the reader has a solid understanding of the essentials of PHP and SQL, and familiarity with Drupal's administration area. But no advanced PHP or MySQL knowledge is required, nor prior experience creating Drupal modules and themes.

Packt Publishing has made available a Web page for the book, where visitors can order the book (print and electronic copies), download the book's sample code, provide feedback to the publisher, send in a question, read a summary of the book or the table of contents, and obtain a sample chapter (Chapter 2 — "Creating Our First Module"). One would expect to find a link to errata reported for this specific book, but this page does not have such a link. In fact, none of the book profile pages on Packt Publishing's site appear to have links to their respective errata. Instead, the visitor must go to their support page, specify the book of interest (the drop-down list should default to the last book review, but it does not), and finally click on the errata link, which should have been on the individual book's page. After clicking a link, a small and non-resizable browser window pops up, listing the known errata.

To Web developers unversed in Drupal's architecture and the use of modules to extend Drupal's core capabilities, the first chapter of this book should be quite valuable, because the author explains how Drupal's functionality has been logically organized into modules. For developers unfamiliar with CMS modules, the author sums it up nicely: "A module is a bundle of PHP code and supporting files that use Drupal's APIs and architecture to integrate new functional components into the Drupal framework." As noted earlier, the author presents overviews of the most critical Drupal concepts, including core modules, hooks, themes, nodes, comments, users, blocks, page rendering, menus, and forms. Unlike what is found in far too many programming books, the explanations in this chapter are generally quite complete, authoritative, and clear — with the exception of the last note on page 8 pertaining to system modules. The chapter concludes with a brief discussion of the demonstration site created in the book, as well as some developer tools recommended by the author.

In the second chapter, readers learn the basics of creating a module — in this case, one that accesses a philosophy reading list from Goodreads. Anyone who does not yet own a copy of the book, can quickly see the overall style of the book's information and presentation, by downloading the aforementioned sample chapter. There are few blemishes in this chapter: A short (and apparently non-facetious) phrase in one of the notes, "Drupal is meticulously documented..." (page 30), should come as a surprise to anyone who has stumbled into one of the gaps in Drupal's online documentation. The reader should beware that the code for the two private functions used in the sample module, differs between the book's code and that in the download archive, with no indication to the reader from either source as to which is to be preferred, if any. The book's code has other problems, as described in the errata. Also, tags such as "<channel/>" and "<item/>" may give the reader a false impression that those are empty tags (i.e., single tags, and not paired open/close tags). Unfortunately, this nonstandard and confusing notation is used throughout the book.

Theming a Web site is an important part of making it attractive and more usable to site visitors, and Drupal, like any solid CMS, has built-in support for applying themes to a site. In the third chapter, the author explores Drupal's theme system and theme engines, as well as how to create a new theme, and how to use Drupal's hook system for overriding a template function. The discussion is better than that seen in any other book, but could be further strengthened if the author were to explain the reasoning behind some of the suggested practices, such as making redundant copies of a parent theme's images for a sub-theme. Any readers implementing the "descartes" sub-theme should note that template.php, in the download code, begins with "<?" and not "<?php," which will cause problems if their PHP has short_open_tag set to Off. Chapter 5 extends the ideas presented earlier, and shows the reader how to create a new module with a default theme. The discussion of how to register a theme and, more specifically, the naming conventions, is in some places rather turgid — not due only to the writing, but partly Drupal's overriding scheme. But it does not help to have array keys such as "theme_function_name" mentioned in the text but not in the code (should it be "<theme function name>," following his earlier naming convention?). Partway through the fourth chapter, the author acknowledges that the reader may be getting lost in the terminology, and clarifies it. This is a worthy practice that could have been employed in several other places in the book (and by the authors of other programming books).

In the fifth chapter, readers will find a detailed discussion of how to leverage the power of AJAX, jQuery, and JSON to allow modules to refresh with changed content, without requiring Drupal to reload the entire Web page. Chapter 6 explains how to create a module with an administration interface, as well as how to use the powerful Forms API (FAPI), and the Mail API, among other Drupal capabilities available to the programmer. Creating a nontrivial content type that incorporate specialized fields, is the subject of Chapter 7. It is accomplished by building a new module, rather than the more common approach of using the Content Construction Kit (CCK). Readers will also benefit from an introduction to the Schema API, which is valuable for generating database-neutral SQL code. In Chapter 8, the author explains how to create content filters, actions, and hooks, as well as how to assign a trigger to an action. Like the previous two chapters, this one is fairly long and takes some work to fully digest, but doing so is essential for learning how to make the most of hooks, among the other topics. The author also shows how to indicate that your new module depends upon others. The final chapter covers installation profiles and packages, which allow the developer to put together a customized version of Drupal containing the new modules he or she has created, in addition to any dependent non-core modules.

Overall, Learning Drupal 6 Module Development accomplishes its primary goals, and provides information that would even be of interest to Drupal developers who may have no intention of ever creating their own modules and themes, but who would like to learn a lot more about Drupal's underlying architecture, and some of the differences between versions 5 and 6. The author tackled a difficult subject area, and presents enough explanations that would allow any experienced PHP programmer to work through the examples and learn from them. There are plenty of screenshots and diagrams, all of which are helpful. However, a few of the screenshots are intended to show color changes, which makes no sense because all of the screenshots are grayscale only. Rather than choosing orange and pink and other colors, distinct shades of gray would probably have been a better approach.

The book's remaining flaws — aside from those noted above — are relatively minor. The chapter summaries are of no value, and could be dropped in the interests of making the book leaner. Some of the paragraphs are overly short, and should be combined with adjacent ones (e.g., "Here is one very good reason."; page 111). Some of the phrasing is weak (e.g., "has got better and better"; page 18), confusing (e.g., "a typical template work"; page 60), or incorrect (e.g., "uninspiring"; should read "uninspired"; page 70). Other similar problems are identified in the book's errata. The author misses many opportunities to use commas to improve the text's readability, and even uses them incorrectly with parentheses (page 64). Some proper names do not have correct title case, such as "Windows explorer" (page 35). Throughout the manuscript, "hookname" should instead read "hook name." The possessive term "its" should contain no apostrophe (page 185, for example). Occasionally, a (non-critical) word is missing, such as in "content is main content" (page 33). Yet in none of these instances should the alert reader be unable to determine what the author is stating.

None of the weaknesses identified above detract from the overall value of the book. As of this writing, Learning Drupal 6 Module Development is the most promising and information-rich resource for Drupal developers interested in creating their own modules and themes.

Michael J. Ross is a Web developer, writer, and freelance editor."

You can purchase Learning Drupal 6 Module Development from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

cancel ×

39 comments

Sorry! There are no comments related to the filter you selected.

umm (4, Insightful)

Brian Gordon (987471) | about 6 years ago | (#24964897)

Wouldn't this topic be appropriate for online documentation, not a for-pay book?..

Re:umm (1)

larry bagina (561269) | about 6 years ago | (#24964945)

Just download the torrents. It's not our job to support their outdated distribution system. They should be giving the book away for free and make money by selling tshirts at LUG meetings.

Re:umm (0)

Anonymous Coward | about 6 years ago | (#24965741)

Wouldn't this topic be appropriate for online documentation, not a for-pay book?

Have you read the Drupal documentation? It's atrocious.

(This isn't just random flamebait. I tried to learn Drupal, as it seemed like a well-respected CMS, but the documentation turned me off. Way off.)

Re:umm (1)

FooBarWidget (556006) | about 6 years ago | (#24966407)

And why should the author give documentation to you for free? Should he not be rewarded for his time? What's in it for him to do all that for you for free? If you were him, would you spend so much time giving freebies to people who don't appreciate the fact that you've already given them free code in the first place?

And no, I'm not a Drupal developer or even a Drupal user.

Re:umm (1)

poppen_fresh (65995) | about 6 years ago | (#24967931)

Like most technologies that get books, Drupal does have great online documentation. I think the idea here is that the author can give some sort of expert advice/explanation/whatever that goes above and beyond the online docs.

http://drupal.org/handbooks [drupal.org]

Re:umm (2, Insightful)

Se7enLC (714730) | about 6 years ago | (#24968301)

Drupal does have great online documentation.

You clearly haven't tried to use it for anything... It's mostly out of date and referencing old versions (5.x and 4.x). Drupal is a great codebase, but they change APIs far too often to allow the documentation to keep up.

If you ask for advice in the IRC chat or on the forums/groups, you'll just hear "buy and read the book and don't write anything else until you've read it".

So yeah, "The Book" is an invaluable resource, I'm sure, but I'm with an earlier poster that said this sort of information should be available in their documentation. Physical books on programming topics should be reserved for the teaching and techniques, not the only place to get a tutorial on the basics.

Re:umm (0)

Anonymous Coward | about 6 years ago | (#24969507)

Let me second that.

There is an embarasment of riches of documentation on the drupal site which makes it hard to see the forest through the trees.

I didn't understand drupal at all until I got the book. Of course right after I got the drupal 5 book they released drupal 6.

Re:umm (2, Informative)

xanadu113 (657977) | about 6 years ago | (#24974139)

They now have the Pro Drupal Development book in 2nd edition, which covers Drupal 6.. (and is quite a bit thicker than the Drupal 5 version...)

Re:umm (1)

karlconnors (1352873) | about 6 years ago | (#25032355)

and what do you do when you are on a plane? on a bus? subway? Red Sox game/... all without bandwith

Summary: (0)

Anonymous Coward | about 6 years ago | (#24964979)

The book is poorly written, but -- unlike most of its ilk -- is at least marginally useful. Hooray!

Brewers Drupal (0)

Anonymous Coward | about 6 years ago | (#24964999)

Unless Drupal already does more or less exactly what you need, it's probably as fast to author some code from scratch (or use a framework) rather than learn Drupals API. As such, I suspect this book has a limited market.

Re:Brewers Drupal (2, Insightful)

caramelcarrot (778148) | about 6 years ago | (#24965129)

Although that is true, I personally find that the Views 2 and CCK module for creating your own content types is the most important thing. Often you find yourself with a site that is almost a blog/news type site, but in need of sticking on some extra fields or views, and both those modules make it very easy in-interface. I've used CCK to make a system to list universities socities and clubs, list events, list sports results, list film showings (integrated with google checkout, so including fields for price, tickets available, booking closing time and all that). It's all tremendously flexible and helps to get a very large proportion of the sites that you'd want to make. I'll acknowledge that it isn't suited if you want to do something fancier - I wrote an online college accomodation database from scratch in php - with surveys, choice lists and balloting. It might've been possible in drupal, but it would have been pushing it quite a bit.

Re:Brewers Drupal (1)

caramelcarrot (778148) | about 6 years ago | (#24965157)

And for some reason, slashcode has removed all my linebreaks...

Re:Brewers Drupal (0)

Anonymous Coward | about 6 years ago | (#24965389)

They're still there. Your browser treats them as whitespace though.

Re:Brewers Drupal (1)

Raenex (947668) | about 6 years ago | (#24982853)

I recommend Plain Old Text mode and using the Preview button.

Re:Brewers Drupal (1)

topham (32406) | about 6 years ago | (#24965319)

meanwhile, I've setup Drupal 6, installed CCK, and Views 2 and they dman fields from CCK aren't showing up so I can't use them in Views...

somebody shoot me.

Re:Brewers Drupal (1)

MightyYar (622222) | about 6 years ago | (#24965397)

somebody shoot me.

I'm sorry, but for insurance reasons I need a signed, witnessed, and notarized confirmation before I can take action on your request.

Re:Brewers Drupal (1)

Reorix (1184073) | about 6 years ago | (#24965895)

Although this is probably better left for Drupal support forums... Try going to the User Administration -> Permissions page, and set appropriate permissions for the fields. They default to no one having permission, so they never show up. ^_^

Re:Brewers Drupal (1)

fiannaFailMan (702447) | about 6 years ago | (#24965353)

Unless Drupal already does more or less exactly what you need, it's probably as fast to author some code from scratch (or use a framework) rather than learn Drupals API. As such, I suspect this book has a limited market.

So you've used Drupal then? How do you find it?

Re:Brewers Drupal (0)

Anonymous Coward | about 6 years ago | (#24965727)

Admittedly it has been some years since I used drupal. What initially appealed to me about it was powerful content classification (taxonomy) and then along came that Shirky essay. [shirky.com] So I found myself thinking differently about the areas that (for me) drupal was strongest in.

These days, it's possible to set up a functional app using scaffolding etc... faster than you can scratch the surface of the Drupal API. By comparison, the API for my framework is a simple class loader and I'm not left fighting with any underlying assumptions about how the finished site should work.

Cheers

Drupal User Here (2, Informative)

mpapet (761907) | about 6 years ago | (#24966703)

There are some things I like about it, like the whole taxonomy thing. I'm running 6.x now and it's much faster than 4.x and better to administrate.

It's very true that drupal sites look and feel quite alike. The theming has gotten better, but still, they are all quite similar. The canned forums and mailing list manager I still don't like. Almost every contributed module relies on mysql, so ignore their claims of PGSQL.

I would say that if Drupal can do your task with a few modules, it's great. If it can't, then find another CMS that can. If there is no CMS that does what you want, you may be better off starting from scratch.

Re:Drupal User Here (1)

Mouse42 (765369) | about 6 years ago | (#24967943)

"the look alike" phenomenon is from poor front end developers who won't put in the energy for theming. My website is built in Drupal [kmgallery.net] , and doesn't look like any other Drupal site out there.

Re:Drupal User Here (0)

Anonymous Coward | about 6 years ago | (#24968817)

Hi,

How do you make the current category be highlighted for sub-pages ?

My first try was to create hierarchies in the primary links, but when entering a sub-page, the menu it belongs to doe not remain highlighted.

I would appreciate if you could give me a hint.

Thanks!

PS: Nice photos, especially "Break Free" and the infra-red serie.

Re:Brewers Drupal (1)

Zwicky (702757) | about 6 years ago | (#24971801)

So you've used Drupal then? How do you find it?

How do I find it? I find it here [drupal.org] .

Haha, I kill myself. No seriously though, I find it to be quite a useful system. What I find irritating is the online documentation and the Drupal programmers' proclivity for changing things for seemingly tenuous or no reason, creating unnecessary headaches for those who must now update their own modules.

Anyone wanting to maintaining backwards compatibility for whatever reasons is in for some headaches.

If you have the book handy I find that the problems are minimized. Owning the book that develops against version 5 I balk at having to buy a new book for version 6 but it looks like I will have to as problems just keep arising and finding answers takes time.

Maybe I'm just a cynic but it makes me think that the changes and incomplete and/or outdated online docs are an intentional plot to sell more books.

But I will say that if you can get past the initial bumps and potholes on the path to learning Drupal it can be quite pleasant to use and develop for. YMMV but in my experience until they document things properly on drupal.org the book, while not perfect, is essential and conducive to productivity. You will lose less hair and accomplish more in less time.

Dogfood. (0)

Anonymous Coward | about 6 years ago | (#24965359)

"Of all the content management systems (CMSs) that a Web developer could use for creating a new site"

So what does Slashdot use?

Drupal Camp LA this weekend 9/13-14 at LA Conv ctr (1, Informative)

Anonymous Coward | about 6 years ago | (#24965611)

BTW -

For those interested in Drupal, there
is a FREE Drupal Camp in Los Angeles
Calif this weekend.

When: Sat-Sun 9/13-14
Cost: Free (RSVP req so please hurry)
Parking: at LACC - $12?, cheaper a few blocks away, or try the metrorail.

More info
http://drupalcampla.com/

also, for those in the LA area Thu nite, 9/11/08 the SGVLUG has their monthly meeting in Pasadena, main topic mythTV, other topics - anything which maybe covered on /. ;) www.sgvlug.org

Re:Drupal Camp LA this weekend 9/13-14 at LA Conv (1)

EmperorKagato (689705) | about 6 years ago | (#24965949)

Why are you posting as Anonymous Coward?

Re:Drupal Camp LA this weekend 9/13-14 at LA Conv (0)

Anonymous Coward | about 6 years ago | (#24970343)

What difference does it make? Do his words have different meaning to you if they come from "SuperCoolLinuxFreak"?

Re:Drupal Camp LA this weekend 9/13-14 at LA Conv (1)

EmperorKagato (689705) | about 6 years ago | (#24977031)

No. I wanted to be a fan and now I can't do it.

Drupal vs Joomla (0, Offtopic)

Blimey85 (609949) | about 6 years ago | (#24965625)

About a year ago I was looking into using a CMS for a couple of sites and it came down to Drupal vs Joomla. I kept hearing how great Drupal was and how Joomla was nothing but a security headache but in the end I chose Joomla because it seemed to have the better community. I'm a programmer and my design skills are limited. I wanted something that had some fairly nice commercial templates available for purchase and for whatever reason, I found a lot more for Joomla than Drupal.

Not wanting to base my decision solely on that, I installed both and gave each a quick run-through. I didn't have weeks to evaluate the merits of each and study the codebase and do all of the things one might do if his job depended on the decision. Instead I just went with my gut and chose the one I felt most comfortable with.

I've since upgraded to Joomla 1.5.x and I've gotta say I'm very happy with the choice I made. Joomla has done everything I've asked of it and I've been able to find some really nice templates for each site I've done. Is it perfect? No, far from it, but it's a fine piece of software. Is it better or worse than Drupal? I dunno. I don't think anyone can answer that conclusively as it's subjective. I just wish Joomla would add some of the features that Wordpress is sporting these days... Google Gears and installation/updating via svn.

Re:Drupal vs Joomla (0)

Anonymous Coward | about 6 years ago | (#24965799)

I've installed and put both into production. I've come to the conclusion many of the Drupal devs were drunk when they wrote their code. It works in the end, but it often stumbles drunkenly on it's way there.

Joomla is just buzzed a little.

Re:Drupal vs Joomla (1)

Mystery00 (1100379) | about 6 years ago | (#24965885)

Similar story but the other way around for me, I found Drupal to be much easier to develop with than Joomla, this was back when I first dived into the world of website development. Especially the documentation of Drupal, at the time, far surpassed Joomla's.

To me Drupal seems a lot cleaner, simpler and tidier while Joomla is a mess. I'm not sure whether the documentation is better now or not, but a year or so ago it was impossible to figure out how to develop for it.

Since my original comparison I never gave Joomla another second of thought.

Let me tell you a little story (0)

Anonymous Coward | about 6 years ago | (#24966197)

Our webshop decided to use drupal for a complex website. I read the book, thinking that it will help me along the task which it did, even though we were using drupal 5. But because drupal was so popular, I was able to implement the functionality on top of existing modules such as node_relativity and cck.
However integrating the design, was a pain. There's absolutely no easy way of doing some trivial tasks, like setting the active tab on a webpage, or creating a fancy login/register page(1). You have to write dirty php code. Overiding functions, unseting variables, for every freaking form, just to do some simple things, such as hiding some labels.
It's counter productive, and it's a shame; that's why I can spot a drupal website a mile away.

--
1. Someone will say, that i'm wrong, that drupal provides an active class. However the tabs were images(a large sprite, with on hover/active statuses). Go figure - IE6 can't read multiple classes, picking up only the last one; Since i had a list, I needed the active element on the list element (li) rather than the a href link

Butchered (0)

Anonymous Coward | about 6 years ago | (#24966681)

I read that as "butchered, by Matt Author".

eZ publish ? (0)

Anonymous Coward | about 6 years ago | (#24969433)

I always think it's weird that eZ publish is not mentionned in the comments... I guess that being both commercial and opensource is not always good ;)

Re:eZ publish ? (1)

blakhol (919393) | about 6 years ago | (#24970325)

Or perhaps it is because the thread is not about eZ publish.

don't bother (1)

xombo (628858) | about 6 years ago | (#24986937)

Don't spend your time learning Drupal.

It is by far one of the most poorly organized CMS products out there.
If 6 is anything like previous versions, be prepared for lacking documentation, security holes, incompatible plug-ins, spaghetti and meatballs code, and a PHP 3/4-esque procedural coding style totally devoid of objects.

If that suits your fancy and you are a consultant looking to charge your clients ever-increasing rates, then by all means--go for it.

Re:don't bother (1)

karlconnors (1352873) | about 6 years ago | (#25032407)

>>>be prepared for lacking documentation well, isnt that what this book tries to fix??

Bay Area Drupal Camp also coming up in October (1)

stephthegeek (733850) | about 6 years ago | (#25012751)

More info: http://www.badcamp.net/ [badcamp.net]
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>