Preface

Audience

Who is this book written for?

  • If your lead developer can’t seem to shut up about this weird “Drupal” thing, and you want to figure out what on earth she’s talking about, this book is for you.

  • If your boss has approached you and said, “We need to build a site that has X, and fast!” and “X” is a photo gallery, a product reviews section, an ecommerce store, or any of the other projects covered herein, this book is for you.

  • If you know your way around Drupal, but have found yourself paralyzed by the sheer volume of contributed modules, and need help figuring out which ones are worth looking at, this book is for you.

  • If you consider yourself well versed in Drupal already, but want to broaden your horizons by learning about some useful modules that you may not have encountered yet, and learn best practices for building powerful Drupal websites, this book is for you.

  • If you’ve been building Drupal sites for a while in Drupal 6, but are new to Drupal 7 and want to find out what’s new and different, this book is for you.

If you’re completely new to creating websites and installing web-based scripts, this book probably isn’t for you, yet. We assume that goofy acronyms like PHP, FTP, URL, ZIP, and HTML are in your working vocabulary. Likewise, if you’re interested in hardcore, nitty-gritty details about Drupal’s API functions, this book isn’t for you: our focus here is on pointy-clicky stuff: combining existing modules to build out functionality, rather than creating new ones.

If you’re one of the rest of us, who fall somewhere between total newbie and computer science professor, we hope that this book provides you with an invaluable reference to building practical websites with Drupal.

Assumptions This Book Makes

You’ll need access to a computer or server running PHP 5.2 or higher, along with a web server (Apache preferred) and database (MySQL recommended). For local development, there are several all-in-one Apache/MySQL/PHP packages available such as WAMP for Windows or MAMP for Macs. Visit http://drupal.org/hosting for a list of Drupal-friendly web hosting companies (with referrals benefiting the Drupal Association), and visit http://drupal.org/requirements to read more about Drupal’s system requirements.

You will also need to install Drupal, and the hands-on chapters assume that you’re using the book’s source code. Appendix A provides some basic instructions, but if you run into trouble or want to read more detailed instructions, see the Drupal installation guide. If you are not using the source code provided with the book, Appendix C contains a list of all of the modules and themes that are used for each chapter so you can re-create them.

A Note About the Modules Used in This Book

Drupal is constantly moving and its community-contributed module world is constantly shifting. The source code for the book provides the versions that the chapters were written with, and as time moves on, the versions available on Drupal.org will most likely change. Sometimes changes don’t dramatically affect how things work, but other times they do. For many chapters, the hands-on sections will apply for a very long time or change so little that they will still be quite easy to follow. But even if the user interface for a module changes dramatically a year down the road, after using this book and walking through various examples, you should be equipped to explore the new functionality on your own. In addition to the specific hands-on “recipes,” you will also learn tips and best practices for how to “cook” generally—that is, how to learn about modules on your own.

Also keep in mind that the Spotlight sections, which discuss module features and comparing modules, along with Appendix B, which discusses how to evaluate modules, provide a good foundation for you to make these evaluations on your own. You can do your own comparisons as newer modules come out and make the best decisions for your use. This book is intended to not only be a guide but also a springboard for your own mastery of the Drupal contributed project world.

Warning

If you are just starting out with Drupal, we highly recommend sticking with the book’s source code, which will always match the book’s text and screenshots. Once you’ve made it through the book’s examples, upgrading to the latest code of the day will then just be a matter of negotiating some minor differences/enhancements around what you already know.

Contents of This Book

Beyond the initial chapter that sets the stage, this book is organized as a series of recipes, each of which consists of the following structure:

Introduction

The introduction gives an overview of what modules are covered, as well as the overall goal of the chapter.

Case study

The case study describes the needs of a fictitious client who requires a website that can track events, have product reviews, or sell T-shirts. We describe some background information about these clients, and go into more detail about their specific requirements.

Implementation notes

Here we discuss various solutions within Drupal to solve the client’s requirements, and go into detail about which modules we’ve selected and why. This section compares and contrasts modules and explains when it’s appropriate to use module A or why module B is a dead end.

Spotlight

Each chapter introduces one or more major modules or Drupal concepts, and the Spotlight sections provide a “bird’s-eye view” of what each specializes in and how it works. Think of this section as a miniature “product sheet” that highlights features of a given module and what it can do. If you’re not interested in a pointy-clicky tutorial but instead want to get an idea of the power and flexibility of Drupal’s top contributed modules, scanning the Spotlight sections should provide what you need.

Hands-on

After describing what a module can do in the general case, the hands-on sections will show you how to configure them by providing step-by-step “recipes” to build out the precise functionality the client requires. If you’re new to Drupal, following these sections will show you exactly how the concepts work in practice, and allow you to build several real Drupal sites yourself.

Taking it further

This section of each chapter provides pointers to other helpful add-on modules that you can introduce to a particular use case to enhance its functionality and make it even more powerful. If you’re extra keen, try experimenting with these modules to make the book’s example projects even better!

Summary

This section wraps up what we’ve learned over the course of the chapter, and provides links to the modules used, and other resources that offer more information.

Here is a list of the book’s chapters and the material covered. The first three chapters are considered “required reading” if you haven’t used Drupal before. The rest of the chapters will assume knowledge of these chapters, including the basics of Drupal and the Views and Field modules. If you’re familiar with Drupal 6 but haven’t yet used Drupal 7, you may also want to skim these chapters, as the user interface and feature set has changed significantly between versions.

Chapter 1, Drupal Overview

This chapter answers the main “need to know” questions about Drupal: what’s Drupal, who’s using it, why are they using it, and how does it conceptually work? It also provides some historical context to Drupal, introduces essential terminology, and covers everything else you need to get up to speed.

Chapter 2, Drupal Jumpstart

The first hands-on chapter hits the ground running, and will show you how to use Drupal’s core functionality, as well as a few contributed modules, in order to build a basic business website. By the end of this chapter, you should feel comfortable with Drupal’s core functionality and navigating the administrative section.

Chapter 3, Job Posting Board

This chapter introduces the Field and Views modules by walking through the construction of a job-posting website. You will also learn to extend core’s Field module with additional contributed modules. By the end of this chapter, you’ll understand how to create custom content types and add form fields, as well as how to click together lists of any type of website content, which are the basis of all the other chapters in the book.

Chapter 4, Media Management

This chapter helps you build a record review site, with images and videos, using core’s Image module along with several contributed media modules.

Chapter 5, Product Reviews

In this chapter, you will build a community product review website, with the Amazon module providing the product data, and the Voting API and Fivestar modules providing a rating widget.

Chapter 6, Event Management

This chapter’s all about how to do event management in Drupal, featuring the Date and Calendar modules for storing and displaying event information, and the Flag module for keeping track of who’s coming.

Chapter 7, Managing Publishing Workflows

This chapter talks all about implementing custom publishing workflows with the Workbench module, and uses core’s Taxonomy as well as Pathauto to organize our content.

Chapter 8, Multilingual Sites

This chapter describes how to build a multilingual site using the Locale and Content Translation modules and the Internationalization (i18n) suite of modules.

Chapter 9, Online Store

In this chapter, you’ll use the powerful Drupal Commerce package to build a T-shirt store that includes such features as a product catalog, shopping cart, and payment processing.

Appendix A, Installing and Upgrading Drupal

If you’re new to Drupal, this appendix will get you up to speed on how to install it, as well as how to do upgrades down the road.

Appendix B, Choosing the Right Modules

Evaluating modules is often the biggest hurdle to building a Drupal site. This appendix is a breakdown of strategies and tips for figuring out which module will work for your needs.

Appendix C, Modules and Themes Used in This Book

This appendix lists the modules and themes used in each chapter, for easy reference.

Appendix D, Major Changes Between Drupal 6 and 7

This appendix covers the big changes that happened between Drupal 6 and 7. It lists new features, existing features that were modified, as well as a few gotchas and functionality that has been removed from core in Drupal 7.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates filenames, directories, new terms, URLs, and emphasized text.

Constant width

Indicates parts of code, contents of files, commands, and output from commands.

Note

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Any navigation around Drupal pages is displayed as follows:

Structure→Content types (admin/structure/types)

This is an instruction to click the Structure link in the administrative toolbar, then click the Content types link. As a shortcut, you can also enter the path indicated in parentheses into your browser—http://www.example.com/admin/structure/types or http://www.example.com/#overlay=admin/structure/types—to view the page in the administrative overlay.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation.

All Drupal code, including the Drupal 7 code that you can access through the O’Reilly website (as described shortly) is subject to the GNU General Public License, version 2. Your use of Drupal code, including copying, modification, and distribution, is subject to the license. “Drupal” is a registered trademark of the founder of the Drupal project, Dries Buytaert. Information about permitted uses of the code and the trademark can be found at the Drupal website, where you can also find information about how the GNU General Public License affects your use of the code. More information about the license is available at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html#SEC3.

With respect to other code examples in this book, you do not need to contact us for permission unless you’re reproducing a significant portion of the non-Drupal code. For example, writing a program that uses several chunks does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Using Drupal by Angela Byron, Addison Berry, and Bruno De Bondt. Copyright 2012 Angela Byron, Addison Berry, and O’Reilly Media, Inc., 978-1-449-39052-5.”

If you think that your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Downloading the Book’s Source Code

This book’s website contains a link to a downloadable copy of Drupal 7, along with all of the modules covered in the book, and the themes used in the example websites for each hands-on chapter, at http://usingdrupal.com/source_code.

Each hands-on chapter also has an “installation profile” (a set of starter scripts that configure default options) that bootstraps a starter site for each hands-on chapter with some basic preconfiguration. These installation profiles may be selected at the beginning of the Drupal installation process; for example, Chapter 3: Job posting board.

Switching between one chapter’s hands-on examples and another’s requires making a new site while using the same source code. You can do so with minimal fuss using the following steps:

  1. Create a new database for the chapter’s installation of Drupal.

  2. Change the permissions on sites/default/settings.php so that the file is writable.

  3. Copy sites/default/default.settings.php to sites/default/settings.php, overwriting the existing settings.php file.

  4. Rerun the installation at http://www.example.com/install.php.

More information on how to install Drupal is available in Appendix A.

In addition to configuring some basic settings such as the site name, the theme, and so on, for each chapter, the installation profiles (with the exception of Chapter 2) also set up the following users:

username: admin, password: oreilly

The first user, who is in the “site administrator” role; can do everything on the site

username: editor, password: oreilly

A user in the “editor” role; used for chapters that require users with elevated permissions

username: user, password: oreilly

A normal user in only the “authenticated user” role

It is these users the chapters refer to when the instructions reference logging in as the “editor” user, or similar. Unless otherwise specified, it is assumed that steps are completed as the “admin” user.

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://oreil.ly/using-drupal-2e

To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

First, some general kudos. We would like to thank the book’s technical reviewers, Ryan LeTulle and Peter MacIntyre. Thanks to Julie Steele and Meghan Blanchette from O’Reilly, who guided us through the process of updating the book as well as being ever patient and helpful. And, of course, thanks to Dries Buytaert for inventing and open-sourcing Drupal; without him, none of this would have happened.

Addison Berry would like to thank her parents, Merlin and Joan Berry, for always believing in her and supporting all of her crazy pursuits in life, and Camilla Krag Jensen for being a constant anchor, and being patient with Danish translations, both for the book and daily life. Big thanks also to Lullabot for supporting her Drupal habit.

Angela Byron would like to give tremendous, heartfelt, grovelling thanks to her awesome wife, Marci McKay, for her endless patience and support of Angie’s insatiable Drupal addiction. Huge thanks also to her family, particularly Jeanne, Sara, and Keith Byron, for all of the support both with the book and with life in general. And finally, she would also like to dedicate this book to her father, Mike Byron, who passed away very suddenly in August 2011, leaving behind a legacy of thousands of lives changed. Keep on rockin’ in your big yellow Firebird in the sky, Dad.

Bruno De Bondt would like to thank his partner Ariane Khachatourians for love, patience and so many other things—“Home is wherever I’m with you.” Also thank you to his parents, family and friends for inspiration and support for all he does, like moving halfway across the world. Big thanks also to the Drupal community for being amazing and building fantastic open source software.

Get Using Drupal, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.