Tải bản đầy đủ (.pdf) (480 trang)

Leveraging Drupal pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (14.15 MB, 480 trang )

Leveraging Drupal
®
www.wrox.com
$49.99 USA
$59.99 CAN
Wrox guides are crafted to make learning programming languages and technologies easier than you think. Written by
programmers for programmers, they provide a structured, tutorial format that will guide you through all the techniques involved.
Recommended
Computer Book
Categories
Internet
Web Page Design
ISBN: 978-0-470-41087-5
As an open source, community-based content management system
and web site application development framework, Drupal allows
you to create interactive, media-based, database-driven web sites
that become a part of everyday activities and communications.
This unique book is the first of its kind to tackle the challenging
task of leveraging Drupal to get a site done right and make that site
work for you, based on industry-wide software development best
practices.
Within these pages, you will gain insight into how to work with any
release of Drupal, approach your project, establish a development
environment, plan for deployment, and avoid pitfalls along the way.
A real-world example of a web site application based on Drupal—an
online Literary Workshop—is used throughout the book, and it walks
you through the entire development lifecycle. You’ll learn how to
bring your web site into the exciting Drupal mainstream, customize
Drupal for your specific needs, and even make “non-Drupal” looking
sites. With this hands-on guide, you’ll discover how to use Drupal to
efficiently publish, manage, and organize a wide variety of content


on your web site.
What you will learn from this book
● Best practices to optimize the way you approach
development projects
● Methods for setting up a development environment
using version control and issue tracking tools
● How the Drupal theming system works and how it
separates content from presentation and style
● Techniques for upgrading and deploying the online
Literary Workshop
● The future of Drupal and how it might be developed
and used
Who this book is for
This book is for Drupal users of all levels of expertise
who are looking to put together a sophisticated web
application.
Leveraging Drupal
®
Kane
spine=.96"
Updates, source code, and Wrox technical support at www.wrox.com
Leveraging
Drupal
®
Getting Your Site Done Right
Victor Kane
Wrox Programmer to Programmer
TM
Wrox Programmer to Programmer
TM

www.it-ebooks.info
spine=.96"
Get more out of
WROX.com
Programmer to Programmer

Interact
Take an active role online by participating in
our P2P forums
Wrox Online Library
Hundreds of our books are available online
through Books24x7.com
Wrox Blox
Download short informational pieces and
code to keep you up to date and out of
trouble!
Chapters on Demand
Purchase individual book chapters in pdf
format
Join the Community
Sign up for our free monthly newsletter at
newsletter.wrox.com
Browse
Ready for more Wrox? We have books and
e-books available on .NET, SQL Server, Java,
XML, Visual Basic, C#/ C++, and much more!
Contact Us.
We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing
www.it-ebooks.info

Leveraging Drupal
®
Introduction
xxiii
Part I Launching Your Website as a Software Project
Chapter 1: Keeping It Simple 3
Chapter 2: Taking Baby Steps
17
Chapter 3: Getting Organized
53
Chapter 4: Getting up to Speed
87
Part II Getting Your 5.x Site Up-To-Date
Chapter 5: Finishing up the Elaboration Phase 109
Chapter 6: Pushing the Envelope
129
Chapter 7: Becoming an Expert Drupal Themer
155
Part III Upgrading Your Drupal Site
Chapter 8: Upgrading to Drupal 6 187
Chapter 9: Upgrading to Drupal 6 Revisited
213
Part IV Getting the Most out of Drupal 6.x
Chapter 10: Installing and Using Drupal 6 Fresh out of the Box 239
Chapter 11: Full Swing Agile Approach to Drupal Development
279
Chapter 12: The jQuery Chapter
323
Part V Drupal 7 and the Road Ahead
Chapter 13: From Drupal 6 to Drupal 7 and Beyond 365

Chapter 14: Deploying your Application as a Drupal Installation Profile
385
Chapter 15: Acquia Drupal as an Enterprise-Ready Alternative
411
Index
431
www.it-ebooks.info
www.it-ebooks.info
Leveraging Drupal
®
www.it-ebooks.info
www.it-ebooks.info
Leveraging Drupal
®
Getting Your Site Done Right
Victor Kane
Wiley Publishing, Inc.
www.it-ebooks.info
Leveraging Drupal
®
: Getting Your Site Done Right
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-41087-5
Manufactured in the United States of America

10987654321
Library of Congress Cataloging-in-Publication Data
Kane, Victor, 1946-
Leveraging Drupal : getting your site done right / Victor Kane.
p. cm.
Includes index.
ISBN 978-0-470-41087-5 (paper/website)
1. Drupal (Computer file) 2. Web sites — Design — Computer programs. 3. Web site development. I. Title.
TK5105.8885.D78K36 2009
006.7

6—dc22
2008049818
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under
Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the
Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222
Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission
should be addressed to the permission Department, John Wiley Publishing, Inc., 111 River Street, Hoboken, NJ 07030,
(201) 748-6011, fax (201) 748-6008, or online at
www.wiley.com/go/permissions
.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties
with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties,
including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended
by sales or promotional materials. The advice and strategies contained herein may not be suitable for every
situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting,
or other professional services. If professional assistance is required, the services of a competent professional person
should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an
organization or Website is referred to in this work as a citation and/or a potential source of further information

does not mean that the author or the publisher endorses the information the organization or Website may provide
or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may
have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress
are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other
countries, and may not be used without written permission. Microsoft and SharePoint are registered trademarks of
Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their
respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be
available in e lectronic books.
www.it-ebooks.info
To my parents, John and Helena Kane, who made huge sacrifices in order to guarantee their children’s educations.
To my son, Guillermo, who has taught me so many things. To my loving life partner, Elena, who shares with me
life, love, and struggle, and who has taught me the meaning of determination; and to all our sisters and brothers.
www.it-ebooks.info
www.it-ebooks.info
About the Author
Victor Kane is a process engineer and system architect who focuses on mentoring services and Agile
approaches to web application development. For the past several years, Victor has been building website
applications and helping others to do so using the Drupal CMS Framework, with an emphasis on build-
ing a cookbook of proven recipes capable of meeting modern requirements, based on best practices and
a test-driven approach to application construction.
Victor has been an active participant in the Drupal community, with its forums, locally based Drupal
groups, and Drupal camps and conferences, and is a proud ‘‘graduate’’ of the Drupal Dojo knowledge
sharing group originally founded by Josh Koenig on
.
Since then he has
frequently shared his experience and insights on his personal blog,


.
www.it-ebooks.info
www.it-ebooks.info
Credits
Executive Editor
Carol Long
Development Editor
Maureen Spears
Technical Editor
Joel Farris
Dan Hakimzadah
Benjamin Melancon
Production Editor
Rebecca Coleman
Copy Editor
Cate Caffrey
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Barry Pruett
Associate Publisher
Jim Minatel
Project Coordinator, Cover
Lynsey Stanford
Proofreader

Andrew Phillips, Windhaven Press
Indexer
Jack Lewis
www.it-ebooks.info
www.it-ebooks.info
Acknowledgments
The Drupal Community at

, who have managed to bring together a hugely talented
and motivated network of talent, and who owe their success to their ability to begin to transcend national
boundaries, must be a cknowledged in first place.
In second place, the unknown and unwitting poster to the forums and handbooks of
drupal.org
,having
provided the answers in the nick of time on countless occasions.
I must acknowledge also the Drupal Dojo group (
/>), an incred-
ibly selfless ‘‘share the knowledge’’ self-teaching group that started operations in January 2007 and is
now getting ready to launch Drupal Dojo 2.0.
Also, I thank the kind people at Wiley Publishing including Carol Long, who helped me make this book
a reality, and Maureen Spears, who was my lifeline. In addition, I‘d like to convey a word of thanks to the
technical editors — Joel Farris, Dan Hakimzadah, and Benjamin Melancon as well as Robert Douglass of
Acquia — who all were instrumental in shaping the code and text; as well as Miguel Martinez, of Buenos
Aires, who took my photograph for the cover.
All who post. All who test. All who post issues in the Bazaar.
www.it-ebooks.info
www.it-ebooks.info
Contents
Introduction xxiii
Part I: Launching Your Website as a Software Project

Chapter 1: Keeping It Simple 3
Getting with the ‘‘Program’’ 4
Starting with a Map for Business Vision and Scope 7
Who’s Going to Use the Site? 8
What Are They Going to Use It For? 9
What Needs to Be Done So They Can Do That? 10
When Should You Do That? 12
What Should It Look Like? 13
Making Sure You’re Getting What You Really Want 13
Turning Over the Helm 14
Information Architecture and an Agile Approach for the Rest of Us 15
The Example Used throughout This Book 15
Summary 16
Chapter 2: Taking Baby Steps 17
Creating an Initial Environment 18
Installing Drupal as a ‘‘One-Click’’ Pre-Installed Script 19
Installing Drupal Right 22
Whipping up the Initial Prototype 31
Implementing Roles 31
Implementing the Business Objects 33
Putting the First Role to Work (Initial Basic CMS Workflow ) 47
Summary 50
Chapter 3: Getting Organized 53
Reviewing the Initial Environment 53
Housekeeping the SVN Repository and Trac Instance 55
Main Directory Structure for Drupal 56
Main Directory Structure for the Repository 61
www.it-ebooks.info
Contents
Initial Import of the Codebase into the Repository 62

Getting the Test Site up and Running 63
Building on Your Initial Prototype 69
Creating the literary_piece Content Type 70
Enabling Comments for the literary_piece Content Type 71
Creating Some Magazines and Books 73
Setting up Some Forums 78
Setting up Blogs 79
Completing the Primary Menu 80
Committing to the Repository and Tagging the Initial Prototype 81
Deploying to the Test Site 82
Getting Initial Feedback from the Client 84
Summary 85
Chapter 4: Getting up to Speed 87
Finishing the User Stories with the Client 87
Planning the Project 89
Doing It on the Dining Room Table 89
Doing It with Trac 90
Doing It 95
Committing, Deploying to Test, Testing, Tracking 99
Working on the Architectural Baseline 101
Getting the Team Organized and with the Program 103
Whom Do You Need? 103
‘‘Who You Gonna Call?’’ 104
Elaboration Phase Cleanup 104
Summary 105
Part II: Getting Your 5.x Site Up-To-Date
Chapter 5: Finishing up the Elaboration Phase 109
Creating an Initial Environment 109
How Can I Easily Update the Drupal Release? 110
How Can I Update Modules Easily and Cleanly? 111

Whipping up the Initial Prototype 117
A Workshop Leader Can Manage Affinity Groups 119
A Workshop Leader Can Broadcast Messages to Members 125
What’s Left? 126
Working on the Architectural Baseline 126
Summary 127
xvi
www.it-ebooks.info
Contents
Chapter 6: Pushing the Envelope 129
You’ve Got Mail! 129
Using Your Own dev Affinity Group 130
Rolling Your Own Document Case and Index 136
Implementing the Document Case 137
Views-Sorting Tweak 140
Now, Where Were We? 141
Creating the Menus and Navigation Blocks 144
Browsing and Filtering Views of Literary Pieces 145
Example: The Beta Milestone 146
Allowing Filtered HTML Formatting in the Text Area 149
The Tagadelic Module 149
Creating the View Itself 150
Using Exposed Filters with the View 152
Using Categories and Tag Clouds for Project Management 153
Summary 154
Chapter 7: Becoming an Expert Drupal Themer 155
On to Theming 155
Dividing and Conquering Complexity 156
Dynamic Content 160
Specifying Structure 161

Specifying Style 173
Synching Your Work with the Repository and the Test Site 174
Weak and Strong Points in Separation of Concerns with Drupal 178
Standing on the Shoulders of Giants — Reusing the Zen Theme 178
Creating Subthemes 179
Applying the Subtheme to the Quotation Block 181
Summary 183
Part III: Upgrading Your Drupal Site
Chapter 8: Upgrading to Drupal 6 187
Recommended Reading 187
Upgrading — The Basic Process 188
Step 1: Shifting Everything over to a Test Site 188
Installing Using a Complete Backup from Your Hosting 189
Quick and Dirty on the Command Line 189
Step 2: Updating to the Latest Drupal 5.x Version Available 191
xvii
www.it-ebooks.info
Contents
Updating to 5.x Steps 191
The Sad State of My Modules 194
Doing What I Did 195
Step 3: Testing Everything in the Upgraded 5.x Version 199
Step 4: Making a Module Inventory 200
Step 5: Switching to the Default Drupal Theme 201
Step 6: Disabling All Contributed Modules 202
Step 7: Updating the Drupal Core 202
Step 8a: Enabling the Modules 205
Step 8b: Upgrading the Theme 206
Step 9: Re-running All Site Acceptance Tests 211
Step 10: Deploying 211

Summary 211
Chapter 9: Upgrading to Drupal 6 Revisited 213
Shifting Everything over to a Test Site 214
Update Everything to the Latest Drupal 5.x Version 214
Module Inventory for the On-Line Literary Workshop 215
Preparatory Steps before the Point of No Return 216
Physically Replacing the Drupal 5 Contributed Modules 216
Update Drupal Core and Run the Update Script 217
Solving Problems with Organic Groups 218
Escaped PHP Showing up in My Groups View 219
Group Home Pages No Longer Showing the Group’s Posts 222
Getting the Old Views Back 226
Installing the Advanced Help Module 227
Upgrading Your Zen Theme to Drupal 6.x 229
The All-New Devel Module 231
Committing and Deploying to the Test Site 234
Summary 235
Part IV: Getting the Most out of Drupal 6.x
Chapter 10: Installing and Using Drupal 6 Fresh out of the Box 239
Step 1: Installing Drupal — Easier Than Ever Before 240
Downloading Drupal 240
Unzipping and Preparing Files for Upload 240
xviii
www.it-ebooks.info
Contents
Uploading Files 240
Creating the Database and User for the Drupal Installation 241
Running the Drupal Install Wizard 241
Step 2: Designing and Building the Architecture 244
Application Scope and Domain 244

Creating Roles and Users 245
Installing and Enabling Modules 247
Making the Site Bilingual 248
Step 3: Creating the Business Objects 252
Step 4: Creating the Workflows 256
Implementing the Registration Workflow 257
Implementing the Client’s Workflow 261
Implementing the Translator Team Leader’s Workflow 268
Implementing the Translator’s Workflow 272
Summary 278
Chapter 11: Full Swing Agile Approach to Drupal Development 279
Honing the Project Tools 280
Adding an Acceptance Test Node 280
Make a View to List User Stories 281
Making the User List Available 283
Creating a Block Menu to Easily Access the New View 288
Implementing the User Stories 289
Workshop Member: Starting an Affinity Group with Its Own Forums 289
A Publisher Can Browse Public Content 292
A Publisher Can Select Content for Inclusion in a Publication 298
A Publisher Can Manage a Publication 298
A Publisher Can Broadcast a Call for Pieces to be Submitted for a Publication 301
Initial Theming 303
On-Line Blog Functionality 316
Implementing Service Links 318
Implementing the Author Info Block for Individual Blogs 319
Implementing Recent Posts Block 320
Implementing the Blogroll 320
Summary 321
Chapter 12: The jQuery Chapter 323

Anatomy of a Rich Internet Application Framework 323
The Basics 323
Getting at the DOM with CSS 325
Getting at the DOM with JavaScript 327
xix
www.it-ebooks.info
Contents
Anatomy of jQuery and Its Plug-Ins 330
jQuery Itself 330
Our
onload()
Example Implemented with jQuery 331
A Theming Example 332
Plug-Ins 335
Drupal 5.x Uses of jQuery and Other JavaScript Libraries 336
jstools 336
Prototype and script.aculo.us 337
Drupal 5.x UI 338
The jQuery Update Module 338
Advanced Drupal 5.x Examples 339
Reusing the Collapsible Widget 339
Dependent Autocomplete Fields 342
Making Use of Hierarchical Select (Drupal 5.x) 345
Validate, Validate, Validate! 347
Drupal 5.x Thread 347
Drupal 6 Thread: An Ajax-Validated Application Form 349
Drupal 6.x jQuery Breakthrough 354
An Example jQuery Ajax Alarm Module for Drupal 6.x 355
Summary 362
Part V: Drupal 7 and the Road Ahead

Chapter 13: From Drupal 6 to Drupal 7 and Beyond 365
What’s Changed in Drupal 6? 365
Killing the Webmaster 367
Understanding the Drupal Blueprint from Drupal 7 On 368
Making the Historic Decision to Postpone the Drupal 7 Code Freeze 369
Listing the Drupal 7 Features 370
Drupal 7 Architectural Style 371
Drupal 7 Database API 371
Going PHP 5 372
Considering Usability Concerns, Usability Sprints 372
Projecting Drupal 7 Contributed Module Battle Plans 376
Installing Drupal 7 377
Developing a Minimalist On-Line Literary Workshop in Drupal 7 378
Creating Literary Pieces 381
Summary 383
xx
www.it-ebooks.info
Contents
Chapter 14: Deploying your Application as a Drupal Installation Profile 385
Leveraging the Advanced Help Module 385
Analyzing the Components of the Views 2 Help System 386
Planning the On-Line Literary Workshop Help System 387
Implementing the On-Line Literary Workshop Help System 388
Installing Profiles! Kill the Webmaster! 392
What Are Installation Profiles? 392
Analyzing Drupalbin: An Example Installation Profile 392
Writing the On-Line Literary Workshop Installation Profile 395
Starting with a Clean Drupal Installation Tarball 395
Copying in the Modules and the Theme 396
Abstracting out the Views into the litworkshop Module 397

Preparing the ./profile Directory 399
Caveats 410
Creating the Drupal Installation Tarball Itself 410
Summary 410
Chapter 15: Acquia Drupal as an Enterprise-Ready Alternative 411
Trying out Acquia Drupal 412
Step 1: Creating a Subscription 412
Step 2: Setting up Acquia Drupal 413
Step 3: Registering Your Website with the Acquia Network 417
Step 4: Getting Support 421
Exploring the New Acquia Drupal Website Installation 421
Installing Updates 423
Introducing the Acquia Marina Theme 426
Checking out Mollom 427
Using the Acquia Partner Program 429
Summary 430
Index 431
xxi
www.it-ebooks.info
www.it-ebooks.info
Introduction
Drupal is an Open Source, community-based Content Management System (CMS) and Website Applica-
tion Development Framework that allows individuals, organizations, businesses, government agencies,
and social classes to create interactive, media-based database-driven websites where they can carry out a
significant portion of their activities.
What does this mean for you?
T Open Source — Not only is Drupal a software product readily available free of charge, but it
is also licensed under the GPL license. This means, among other things, that its source code is
completely open and readily accessible to all. It also means that all upgrades are available free of
charge.

For more on the GPL license, see
www.gnu.org/licenses/gpl-faq.html
#WhatDoesGPLStandFor
. For an interesting discussion of how business can make use
of GPL-licensed software without having to publish the way they actually put Drupal to
use, see
/>as_i_understa.html
.
T Community-Based — Not all Open Source software is community-based. Some large corpora-
tions release a portion of their code under a GPL license, but the user community cannot partic-
ipate in the production of the code. It is important to understand that because Drupal is actually
produced by a huge developer base, with a publicly accessible and tremendously active issue
queue, Drupal enjoys a considerable gain in the quality of its software.
T Content Management System (CMS) — Once installed and configured, Drupal allows an
authenticated user granted the appropriate permissions to create, edit, manage, and publish
content without any more specialized knowledge than being able to use a modern word
processor. And it allows graphic web designers and stylists to alter the look and feel of that
content.
T Website Application Development Framework — Drupal goes way beyond being only aCMS:
Off the shelf, it allows for the publishing of dynamic content capable of changing and adapting to
different contexts, conditions, or kinds of users. It allows developers to implement web applica-
tions based on business objects and listings generated by flexible, real-time queries generated on
the fly. And it allows developers to integrate the system with countless external web applications
and Web Services in a thoroughly modular fashion.
T Individuals, Organizations, Businesses, Government Agencies, and Social Classes —Ina
word, you. You can use Drupal to create a modern, interactive website that can become part and
parcel of your day-to-day activities and communications.
www.it-ebooks.info

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×