Top Banner
The Definitive Guide to Drupal 7 Benjamin Melancon, Jacine Luisi, Karoly Negyesi, Greg Anderson, Bojhan Somers, Stephane Corlosquet, Stefan Freudenberg, Michelle Lauer, Ed Carlevale, Florian Loretan, Dani Nordin, Ryan Szrama, Susan Stewart, Jake Strawn, Brian Travis, Dan Hakimzadeh, Amye Scavarda, Albert Albala, Allie Micka, Robert Douglass, Robin Monks, Roy Scholten, Peter Wolanin, Kay VanValkenburgh, Greg Stout, Kasey Qynn Dolin, Mike Gifford, Claudina Sarahe, Sam Boyer, and Forest Mars, with contributions from George Cassie, Mike Ryan, Nathaniel Catchpole, and Dmitri Gaskin Apress
29

The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

May 25, 2018

Download

Documents

votram
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

The Definitive Guide

to Drupal 7

Benjamin Melancon, Jacine Luisi, Karoly Negyesi,Greg Anderson, Bojhan Somers, StephaneCorlosquet, Stefan Freudenberg, Michelle Lauer, Ed

Carlevale, Florian Loretan, Dani Nordin, RyanSzrama, Susan Stewart, Jake Strawn, Brian Travis,Dan Hakimzadeh, Amye Scavarda, Albert Albala, Allie

Micka, Robert Douglass, Robin Monks, Roy Scholten,Peter Wolanin, Kay VanValkenburgh, Greg Stout,Kasey Qynn Dolin, Mike Gifford, Claudina Sarahe,Sam Boyer, and Forest Mars, with contributions fromGeorge Cassie, Mike Ryan, Nathaniel Catchpole, and

Dmitri Gaskin

Apress

Page 2: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

Contents

Contents at a Glance iv

Foreword xxxiv

About the Authors xxxv

About the Technical Reviewer..... xli

Acknowledgments xlii

Preface: Why Drupal.. xliii

What's New in Drupal 7? xlvii

How to Use This Book liii

How Drupal Works Ivii

Part I: Getting Started 1

Chapter 1: Building a Drupal 7 Site 3

Planning: Setting Parameters and Knowing Where You're Going 4

Discovery: Why Should This Site Be Built? 4

Information Architecture: Exactly What Will You Build? 5

Design 7

Implementation 8

Installing Drupal 9

Drupal's Administration Menu 12

Appearance: Changing a Core Theme's Color Scheme 13

Extending Functionality with Modules 14

Allowing People to Register and Log In with OpenID 15

Creating Content Types and Adding Content 16

vi

Page 3: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

m CONTENTS

Creating Content 19

Blocks: Creating a Mission Statement 21

Taxonomy: Categorizing Content .....24

Users, Roles, and Permissions 27

Time for a Celebratory Beverage 29

Chapter 2: Essential Tools: Drush and Git 31

A Beginner's Guide to Installing Drush 32

Git: Development Grease 38

Why Git? 39

Installing Git 39

Working with Git 41

Other Useful Git Commands 45

Database Backup Tools 45

Summary 46

Part II: Site Building Foundations 47

i Chapter 3: Building Dynamic Pages Using Views 49

What Are Views? 49

Examples of Views Usage 50

Download, Enable, and Configure Permissions for the Views Module(s) 50

The Views Administration Page 53

Advanced Help Module 53

Action Links 54

Change Which Available Views Are Listed 54

Available Views 55

Deconstructing a View 57

Display Types 58

Views Configuration Detail 59

Overriding: A Views Concept 64

Understanding What Type of Content Will Be Output: Views Filters 64

Advanced Filter Criteria Groups: Combining Sorts with Logical Operators 66

vii

Page 4: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

i CONTENTS

Understanding the Order in Which Content Will Be Output: Views Sort Criteria 67

Understanding What Pieces of Content Will Be Output: Views Format Settings 67

Creating a Basic View 68

The Goal 68

Systematic Approach 69

Set Up the Basics for Your Views 69

Define the Administrative Information 71

Define the Title 71

Define What Type of Content You Want to Display 71

Define What Elements of the Content You Want to Display 72

Define Format Settings 72

Define the Order in Which You Want Your Content to Display 72

Define the Number of Results 72

Add a Menu 73

Define Advanced Settings 73

Preview Your Work 73

Dynamically Editing Your View 73

Admire Your View 74

Add More Features 74

Extend a View 76

Handling the Use Case of Zero Results 76

One Page, Multiple Displays to Highlight First Result 77

Using Tabs for Unique Displays 78

Cloning and Making Administrative Tables Using Exposed Filters 80

Advanced Views Implementations 82

Contextual Filters 82

Relationships 83

Other Modules 84

Exporting to Code 85

Additional Resources 86

Chapter 4: There's a Module for That 87

Modules for Drupal Are Constantly Evolving 87

viii

Page 5: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

» CONTENTS

Fewer Modules Is Better 88

How to Find and Choose a Module 88

What to Do When Something's Wrong with a Module 91

Modules in Core 91

Where to Store Contributed Modules 94

Site Building Essentials 94

Views 95

Pathauto 95

Token (Dependency) 96

Additional Field Types 96

WYSIWYG 97

Webform 98

AntiSpam or Mollom 98

Other Modules That May Prove Useful 99

Administrative Interface and Content Entry 99

Content Display 103

Menus and Navigation 104

Community Building and Social Networking 104

Paths, Search and 404 Errors 106

Miscellany 107

The Beauty of It All 108

« Chapter 5: Creating Community Web Sites with Organic Groups 109

Installing and Configuring Organic Groups 110

Group Content Types 111

Creating Groups 114

Using Views with Organic Modules 115

Creating Group Content 117

Getting Started with Panels 119

Members, Roles, and Permissions .-122

Summary 124

ix

Page 6: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Chapter 6: Security in Drupal 125

Setting Up a Secure Drupal Site 125

Use Strong Passwords 125

Reserve User 1 for Administration Purposes Only 126

Be Cautious When Assigning Permissions 127

Keep Text Formats Tight and Secure 127

Avoid Using the PHP Filter Module 128

Security Process 128

Choosing Modules and Themes: How Secure Are Contributed Projects? 129

Keep Your Code Base Current 132

Writing Secure Code 133

Dealing with Security Issues 135

Summary 136

Chapter 7: Updating Drupal 137

Why Update 137

Preparation 138

Manual Update 139

Follow the Steps in UPGRADE.txt 140

Drush Update 142

Diff Update 143

Contributed Modules 145

Drupal's Automated Module Installer 146

Updating Modules with Drush 146

Summary 147

Chapter 8: Extending Your Site 149

Showcasing Authors with Profile Pages 149

Giving Authors a Headshot Image 151

Linking from Profiles to Web Sites 151

Authors' Other Homes on the Internet 153

A Non-displaying Data Field: Approximate Pages 155

x

Page 7: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

i CONTENTS

Connecting Author Profiles to Authors' User Accounts 155

Giving Authors Permission to Create Profiles 156

Listing the Authors 157

Building the Authors Headshot View 158

Building an Author Biographies View Page, Reachable As a Tab on the Authors View 162

Fine-tuning Content Display 164

Using View Modes to Display the Same Content in Different Ways 166

Modifying Teaser Display and Setting Trim Length 166

Making the Table of Contents with Book Module 168

Setting Permissions for Organizing and Writing Chapters 170

Adding Metadata to the Chapter Content Type with Fields 172

Setting How the Chapter Content Type Displays Its Fields 173

Using Menu Block to Display a Better Table of Contents 176

Adding the Table of Contents to the Main Menu 178

Unking Chapters to Their Authors 178

Adding a Resource Content Type That References Chapters 179

Reusing Chapter's Image Field 179

Allowing People to Attach Generic Files to Content 180

Connecting Content Types with a Node Reference 181

Managing Resource Content Type Display 181

Showing Content That References the Post Being Viewed 182

Giving Faces to the People Posting on Your Site 183

Adding a Text Format That Allows Images 184

Bonus: Making It Easy to Insert Images into Posts 186

Limiting Access to the Suggestion Status Field 187

Autogenerating Human-readable URLs with Pathauto 190

Summary 191

Part III: Making Your Life Easier 193

Chapter 9: Drupal Community: Getting Help and Getting Involved 195

How to Get the Most from Your Participation 196

XI

Page 8: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

a CONTENTS

Where to Find the Community 196

Reading, Listening, and Watching 196

IRC 199

The Issue Queues 201

Summary 202

Chapter 10: Planning and Managing a Drupal Project 203

The Role of Limitations 203

Putting Down Your Concept on Paper 204

1. Discovery 205

2. Information Architecture 206

3. Design 206

4. Development and Implementation 207

5. Content 207

6. Deployment/Launch 207

7. Maintenance 207

Project Management Methodologies and Drupal 207

Taking the Lifecycle into Account on Paper 209

What's a Project Plan? 209

Estimating Completion Dates 211

Risks 212

Minimum Viable Project/Product 212

Keeping Track of Commitments 212

Project Manager Tasks Beyond Development 213

Kickoff Meetings 213

Discovery Meetings 214

Information Architecture/Design Meetings 214

Development Meetings 215

Checkins 215

Milestone Closing Meetings 215

Launch Meetings 216

Post-Project Debriefs 216

Other Tasks for Project Managers 216

Xll

Page 9: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

3 CONTENTS

Creating User Stories 216

Implementing Tasks and Task Workflow 217

Tasks That Make up Milestones 217

Bad Days 218

Further Resources 219

Chapter 11: Documenting for End Users and the Production Team 221

What Makes Good Documentation? 221

Getting Clients into Content Entry Early 222

Creating End-User Documentation Post-Launch 222

The Anatomy of Good Client Documentation 223

Documenting for the Development Team 225

Documenting for the Community 226

The More You Know ...226

Chapter 12: Development Environment 227

Starting with Quickstart 228

Enhancing Your Existing Dev Environment 229

Hosting Your Site Locally 230

Accessing the Command Line 230

Working with Rendered HTML, CSS, and JavaScript 231

Browser and Device Compatibility Testing 232

Working with PHP Files 233

The Most Basic Development Environment 233

Select Hosting Service 234

Uncompressing Archives 238

Server-Side Tasks and Tools 239

Summary 241

^Chapter 13: Putting a Site Online and Deploying New Features 243

Putting Your Site Online 243

1. Export the Database 244

Page 10: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

2. Transfer to Server 245

3. Create a Database on the Server and Import Your Database 245

4. Set the Database Settings in settings.php 246

5. Point Incoming Traffic for Your Domain(s) to Your Site on the Server 247

Before You Go Any Further, Back Up 249

Staging and Deployment 251

Approach 252

The Workflow 252

Bringing Content from Production to Development (and Stage/QA) 253

Bring Code Changes from Development to Stage, then Live 254

How to Put "Everything In Code" 256

Development Workflow Recap 260

Summary 261

Chapter 14: Developing from a Human Mindset 263

Use Revision Control 263

Backup 263

Experiment Freely 264

Contribute 265

Part IV: Front-End Development 267

Chapter 15: Theming 269

The Core Themes Directory 269

Core Themes 270

Theme Engines 273

Theme Administration 274

Enabling and Setting a Default Theme 274

Administration Theme 275

Global Theme Settings 275

Installing a New Theme 277

Defining Theme Metadata (.info Files) 278

Required Properties 279

xiv

Page 11: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

II CONTENTS

Additional Properties 279

Working with Regions 282

Default Regions 284

Hidden Regions 286

Module-Specific Regions 287

Regions and Your Theme 288

Using Regions vs. Hard-coding Variables in Template Files 288

Layout Strategies 289

Template Files 293

Common Core Templates 295

Overriding Template Files 295

Global Template Variables 296

Theme Functions .-..301

How Theme Functions Are Created 301

Calling Theme Functions 302

Overriding Theme Functions 302

Theme Hooks and Theme Hook Suggestions 304

What Is a Theme Hook? 304

Theme Hook Suggestions 305

Suggestions and Template Files 305

Suggestions and Theme Functions 308

Summary 310

Chapter 16: Advanced Theming 311

Finding Available Variables in the Theme Layer 311

Using the Theme Developer Module 312

Preprocess and Process Functions 313

Implementing Preprocess and Process Hooks 315

Finding the Contents of $variables 317

Preprocess Functions in Action 318

Using the Render API 321

What Is a Render Array? 321

Identifying Render Elements •322

xv

Page 12: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Manipulating the Output of Render Elements 322

Notable Render Arrays in Core Templates 326

Introducing renderO, hideO, and showO 327

Theming Forms 329

How Form Markup Is Generated 329

First Steps for Theming Forms 332

Theming Forms with Theme Functions 334

Theming Forms with Template Files 336

Modifying Forms Using Alter Hooks 339

Managing CSS Files 341

Aggregation and Compression 341

Patterns and Naming Conventions 342

Adding, Removing, and Replacing CSS Files 343

Working with Base and Subthemes 348

Creating a Subtheme 348

Inheritance and How It Works 349

Finding a Good Base Theme 349

Tips for Creating Your Own Base Themes 351

Sustainability and Best Practices 351

Start With a Good Base 351

Override Template Files with Purpose 353

Leverage Default CSS Classes 353

Do My Changes Belong in a Module? 354

Summary 354

Chapter 17: jQuery 355

Implementing jQuery and JavaScript 355

Including JavaScript 355

JavaScript Libraries 359

Overriding JavaScript 362

Drupal Behaviors 364

Degrading JavaScript/jQuery Nicely 365

jQuery Ul 366

xvi

Page 13: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

'« CONTENTS

jQuery Ul in Drupal Core 366

Further jQuery Resources 379

Summary 379

Part V: Back-End Development 381

Chapter 18: Introduction to Module Development 383

A Very Simple Module 383

Two Files in a Folder 383

Where to Put a Custom Module 386

Create a Repository for Your Module 388

The .info File 388

The .module File 392

Hooks 393

Technical Skills 398

PHP Basics 398

Terminology 399

Operators and Conditional Statements 399

Control Structures 402

Drupal Coding Standards 404

Development Tip #1: When Something Isn't Working, Clear Caches 407

Development Tip #2: When Anything's Missing, Check Permissions 407

Development Tip #3: Set Your Site to Show All Errors 408

Summary 408

Chapter 19: Using Drupal's APIs in a Module 409

Altering Forms 409

Localization with to and format_pluralO 412

Finding a Drupal Function That Does What You Need 414

Investigating What the Function Gives You 416

Creating a Page with hookjnenuO 421

Choosing a Path for an Administration Page 422

Defining a Page with a Normal Menu Item 422

xvii

Page 14: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Defining a Tab with a Local Task Menu Item 425

Declaring Menu Items for X-ray Module 425

Using Existing Permissions in Your Module 426

Finding Permissions' System Names in the Database 428

Finding Permissions' System Names in Code 430

A Second Local Task to Complement the Default Local Task 431

Call All Implementations of a Hook 432

Format Data for Display as a Table 433

Documenting Themeable Code with ©ingroup tbemeable 433

Making Modules Themeable 435

Resources forTheming in Modules 436

A More Drupal 7 Approach: Leveraging the Power of Render Arrays 436

Calling a Drupal Function Directly 438

Styling Your Module: Adding a CSS File 440

Database API 442

Fetching Data with a Select Query 443

Fetching Data with a Static Query with a Join on Two tables 445

A Non-Database Interlude: Displaying the Same Data in Two Locations 447

Using variable_get() and Another Static Select Counting and Grouping Query 450

Dynamic Queries 450

The .install File 451

Figuring Out Your Data Model 452

Creating a Database Table 453

Inserting and Updating Data 455

Displaying Data in a Sortable Table 456

Drupal Entities: Common Structure Behind Site Components 460

Summary 461

Chapter 20: Refining Your Module 463

Creating a Configuration Page for Your Module 463

Building a Settings Form 465

Defining New Permissions 467

xviii

Page 15: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

SI CONTENTS

Conditionally Taking Action Based on Configuration or User Access 468

Writing a Utility Function when Drupal APIs Miss Your Need 470

Listing Data as Human-Readable, Properly-Punctuated Text 470

Making Mistakes and Embracing Error Messages 472

Searching for Answers 472

Syntactic Fatal Errors 472

Runtime Fatal Errors 473

Tracking Down the Cause of Errors and Warnings 473

Making a Preprocess Function 476

Final Considerations 478

Coder Module Review 478

Peer Review 479

Using hook_help() as Drupal Intended 480

Summary 483

Chapter 21: Porting Modules to Drupal 7 485

Deciding to Upgrade a Module 485

Posting the Issue 486

Why Not Custom Code? 488

Undertaking the Upgrade 488

Keeping Track of What You Need to Know 489

Automating (Part of) the Module Upgrade 489

Identifying What's Wrong 493

Finding Models to Follow 497

Contributing the Upgrade to Drupal.org 498

Chapter 22: Writing Project-Specific Code... 501

Custom Modules 501

Hooks 503

The Method 503

What is it that I need to modify and why am I doing it? 503

Where can I hook into? 504

xix

Page 16: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

What is already there? 504

How can I modify existing functionality for my own needs? 504

An Example: Changing the Label of a Submit Button 505

Specific Use Cases 506

Hiding Elements from the User Interface 507

Execution Order of Hooks 508

Working with Fields 509

Adding Dynamic Front-End Interaction 510

Making Code Reusable 511

Make Functionality Configurable 512

Tie Components Together 513

Document Your Code 513

Follow DrupaPs Coding Standards 513

Release Your Work 514

Summary 515

Chapter 23: Introduction to Functional Testing with Simpletest 517

Advantages (and Caveats) of Using Simpletest 518

When to Use Simpletest 518

What Is Test-Driven Development (TDD)? 519

How Simpletest Works 519

Setting up and Running a Test 520

Anatomy of a .test File 522

Writing Your First Test 523

Running Your First Test 526

Simpletests and Forms 528

The Simpletest API and Further Reading 530

Submitting a Patch to Drupal.org 531

Summary 531

Chapter 24: Writing a Major Module 533

How Not to Build a Module 534

XX

Page 17: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Know the Tools Drupal Gives You 535

Should Your Module Provide an API? 536

Keep API and Ul Separate 536

Use APIs to Hide Complexity 537

Making Your Module Modular 537

Unleashing the Power of Hooking Into Your Module 537

Progressive Enhancement: Making Use of Other Modules If They Are Enabled 538

Getting Started with a Test Environment 539

Stealing Some Code to Start 540

Sharing Your Code in a Sandbox on Drupal.org 541

Planning Your Approach 541

Outlining an API 542

Diving Into Doing 542

Defining Your Data Model 547

How to Store the Data and How to Edit It in the Ul 548

Providing a New Entity Type 549

When to Create an Entity Type 550

How to Create an Entity Type 550

Defining an Entity Access Callback Function 554

Giving Your Entities an Administrative Interface 556

Programmatically Creating and Attaching Fields 559

Finding a Model 559

Define Done 561

Part VI: Advanced Site-Building Topics 563

Chapter 25: Drupal Commerce .....565

Drupal Commerce Overview 565

Key Features 565

Digging Into Drupal Commerce 566

Commerce 569

Price 569

xxi

Page 18: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Dynamic Pricing 570

Product 571

Line Item 573

Product Reference 575

Building a Product Display Node Type 575

Customer 577

Order 577

Payment 578

Enabling Payment Methods 579

Checkout 581

Cart 583

Summarizing the Main Components 584

Implementing Drupal Commerce 585

Development History 586

Design Philosophy 587

Development Standards 588

Building on Drupal 7 589

Core Entities and Fields 589

Forms API Improvements 591

Contributed Module Dependencies 592

Summary 593

Chapter 26: Drush 595

Getting Started with Drush 596

Drupal Site Selection in Drush Commands 597

Drush Alias Files (aliases.drushrc.php) 600

Using the Drush Shell 601

Applying Code Updates with Drush 603

Installing Drush Extensions 606

Going In-Depth with Drush Configuration Options and Aliases 607

Drush Contexts 608

Command-Specific Options 609

Site Lists 609

Page 19: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Using Remote Commands to Deploy Sites with Drush 610

Setting Up an SSH Key Pair 611

Making a Local Copy of a Remote Drupal Site 612

Managing Dump Files 614

Using sql-sync Without Installing Drush on the Remote System 615

Using the Drush Site Context to Control sql-sync Options 616

Scripting with Drush 617

Processing Script Command Line Arguments and Options 618

Running External Commands 619

Processing Invoke Process Results 620

Output and Logging 621

Prompting the User 623

Logging and Error Reporting 624

Writing Drush Extensions 626

The Drush Command Hook 627

Providing the Command Implementation Function 628

Return an Array to Pass Structured Data to Other Drush Scripts 629

Manually Specify the Command Function with a Callback Item 629

Placing the Command Implementation in a Separate File 629

The Drush Help Hook 630

Altering Drush Command Behavior 631

Summary 633

Chciptfir 27" Scdlincj Drupdl••^•••"•635

Do You Need to Care About Scaling? 635

Cache 636

Disabling Caching During Development 637

memcached 638

Varnish 638

On Databases 639

Indexes 640

NULL in SQL 642

A CAP Between ACID and BASE 643

xxiii

Page 20: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

MongoDB 645

Watchdog, Session, and Queue 648

Null Values in MongoDB 649

Summary 650

Chapter 28: Spice Your Content Up With Tasty Semantics 651

Information Overload 651

How Did We Get There? 654

Decentralized Dataspaces 654

Linking Data at the Global Web Scale 655

Do You See What I Mean? 656

RDFa, or How HTML Can Be Augmented with Semantics 656

RDFa, Microformats and Microdata 658

Drupal 7 and the Semantic Web 659

Understanding the Structure of RDF Mappings 661

Working with RDF Mapping Structures 661

RDF Vocabularies in Drupal 7 662

Using RDF Beyond Drupal Core with the Contributed Modules 664

Summary 665

Chapter 29: The Menu System and the Path Into Drupal 667

Drupal's Menu System by Example 667

The Never-ending Path 673

Structure of a Path 674

Callback Functions 676

Loader Functions 677

Fitness 679

Modifying Existing Router Items 680

Summary 683

Chapter 30: Under the Hood: Inside Drupal When It Displays a Page 685

Bootstrap 685

xxiv

Page 21: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

s» CONTENTS

First Bootstrap Phase: Initialize Configuration 686

Second Bootstrap Phase: Try to Serve a Cached Page 687

Third Bootstrap Phase: Initialize the Database Layer 689

Fourth Bootstrap Phase: Initialize the Variable System 689

Fifth Bootstrap Phase: Initialize Session Handling 690

Sixth Bootstrap Phase: Set up the Page Header 690

Seventh Bootstrap Phase: Find out the Language of the Page 691

Final Bootstrap Phase: Load Modules and Initialize Theme 691

Execution of the Page Callback 692

A Typical Example 694

Summary 698

Chapter 31: Search and Apache Solr Integration 699

Search Module Administrative Options 700

Search Results and Facet Blocks 703

Search Module API 704

Hooks Implementations Required to Create a Search 704

Additional Search Module Hooks 704

Apache Solr Search Configuration 707

Enabled Filters 707

Type Biasing and Exclusion 707

Apache Solr Search Customization 708

Hooks for Getting Data into Solr 708

Hooks for Altering Queries and Results 709

Integrating with the Apache Solr Server 710

Managing Data in the Solr Index 710

Searching and Analysis 710

Summary 711

Chapter 32: User Experience 713

Modularity 713

Human API 713

XXV

Page 22: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Memory 713

Long Term Memory 714

Mental Model 714

Perception 715

Gestalt Psychology 716

Law of Similarity 717

Law of Proximity 717

Color 718

Color Harmony 719

Practice 720

The Process 720

The Challenges 721

Concept: What Exactly Are You Building? 722

Wireframes 729

Build: Build an Alpha and Verify with Users 733

Optimize: Observations and New Versions 734

Running the Usability Test 739

Analysis of Results 740

Reporting of Issues 740

Feedback from Issue Queues 741

Release: Project Page and Documentation 741

Copywriting 743

Causes of Unhelpful Copy 744

Principles 745

Chapter 33: Completing a Site: The Other 90% 747

Creating a View Mode 747

Creating a Custom Theming Template 751

Modifying the Chapter Number Field's Display 754

Linking to Drupal.org and Twitter Accounts with Field Formatters 757

Fetching the Username 763

Caching Simple Data Using Drupal's Default Cache Table 765

xxvi

Page 23: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Streamlining an Awkward Form Element with CSS 766

Contextual "Add New" Links for Content Types 767

Finding and Following a Model 767

Noticing and Adopting a Better Way 770

Making a Custom Text Filter 771

Looking for a Module that Does What You Need 771

Choosing an Approach 772

Finding an Example (Hint: the Examples Project) 773

Giving a Module an Interim Name 773

Start a Repository for Your Module 775

Making the Tags and Replacement Markup Form 776

Making Your Own Hook 783

Filtering the Content 783

Renaming Your Module 788

Conditionally Including a Stylesheet for an Administration Page 788

Adding a Container Form Element with a Specified Class 790

Sharing Your Module on Drupal.org 791

Coda on a Contributed Module 792

Making a Site-Specific Module that Uses Your API 792

The Payoff 794

Adding Custom Markup for Output 795

Making Next and Previous Links That Mimic Book Navigation 795

Pulling the Information 795

Creating a View to Make User Pages Have Hackable URLs 801

In Conclusion 802

Chapter 34: Drupal Distributions and Installation Profiles 803

Site Templates 803

Full-Featured Services 804

Development Profiles 804

An Example Distribution: Drune 805

Creating Installation Profiles 806

Structure of an Installation Profile 806

xxvii

Page 24: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Dealing with Configuration: Features 810

Using Installation Profiles and Features as a Development Tool 815

Packaging Your Code 816

Drush Makefiles 816

Hosting on drupal.org 817

Packaging 817

The Future of Distributions 817

Summary 818

Part VII: Drupal Community 819

Chapter 35: Drupal's Story: A Chain of Many Unexpected Events 821

The Original Accident 822

Drupal Gains a Foothold 823

The Extended Weekend from Hell 825

If You Have a Problem, Please Search Before Posting a Question 828

The Story Continues 833

Chapter 36: Now You're in Business: Making a Living with Drupal 835

Building a Drupal Site: New Rules for New Technologies 835

"I Hate Drupal:" Things That Can Go Wrong 835

Understanding Drupal 836

Building on Drupal 838

Ensuring Your Success 841

Building Your Drupal Career 843

Finding Your Place 843

Getting Yourself Out There 844

Out on Your Own: Building a Drupal Business 846

Building a Drupal Career 847

Building Drupal: Making a Living as a Contributor 847

Benefits of "Giving Back" 847

Sustainability Counts! 848

Potential Business Models 849

xxviii

Page 25: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Setting Expectations 851

Getting Better all the Time 851

Chapter 37: Maintaining a Project 853

What's a Drupal Project? 853

Set Up Your Drupal.org Account for Contributing 854

Creating a Sandbox Project 856

Status 856

Project Information 857

Digging in with Git 858

Managing SSH 858

Hack on Your Project 859

From Sandboxville to Projectopolis 861

About Branches and Tags on Drupal.org 861

Preparing a Branch for Your Application 862

Preparing Your Project for Review 862

Applying for Access 863

Receiving Access 864

Summary .864

Chapter 38: Contributing to the Community • • 865

Why Contribute? 866

Without Contributions, There Is No Drupal 867

Taking That First Step 867

Ways to Contribute 869

1. Providing Non-Technical Support 869

2. Sharing Everything 870

3. Answering Questions in Forums, Groups, Mailing Lists, Meetups, and IRC 873

4. Writing Documentation for Drupal.org 873

5. Contributing Patches 874

6. Contributing Code and Design 875

7. Curating Issue Queues 875

xxix

Page 26: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

8. Reviewing the Contributions of Others 877

9. Making Drupal.org Better 878

10. Hosting and Organizing Meetups, Camps, Summits, and More 879

11. Money 880

12. Making the Drupal Community Welcoming 881

Building the Movement 882

Part Villi Appendix 885

Appendix A: Upgrading a Drupal Site from 6 to 7 887

Assess the Situation 889

Content Overview 889

Contributed Modules 890

Create a Plan 891

Run the Upgrade (Again and Again) 891

Preparation 891

Drush Aliases for All Sites Involved in the Upgrade 892

A Middle Way 893

Capturing Additional Upgrade Steps in Update Hooks 896

Optional: Begin the Custom Upgrade Functions from the Drupal 7 Version of the Site's Glue Code

Module 896

Creating an Upgrade Module 897

Enabling Modules in Code 901

Disabling Modules in Code 901

Automating the Fields Upgrade 902

Rerunning the Upgrade 903

Create a Feature 905

Consider Creating a Base Feature Module 905

Building a Feature Module 905

Adding Feature Modules to the Automatic Upgrade 906

Data Migration 907

Managing the Process 907

Understanding the Legacy Data 908

xxx

Page 27: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

i CONTENTS

Specific Sticking Points 909

Initial Analysis 909

Iterate 910

Show 910

Audit 910

Time 910

Launch Day 910

Summary 911

Appendix B: Profiling Drupal and Optimizing Performance 913

User-Perceived Performance 913

What Makes a Web Site Slow? 913

Real Performance 916

Page and Block Level Caching 916

Profiling Drupal, a Primer 917

Slow Database Queries 920

Summary 921

Appendix C: Page Rendering and Altering 923

Step 1: The Router Item 928

Step 2: The Page Callback Is Fired 928

Step 3: The Delivery Callback 928

Step 4: drupal_render_pageO 929

Step 5. hook_page_alterO -929

Step 6. drupaLrenderO 930

Appendix D: Visual Design for Drupal 933

Why Designers Should Work with Drupal 933

Designing for Drupal: What It Means 934

Anatomy of a Drupal Page 934

Design from the Content Out 938

Making Your Life Easier As a Drupal Designer 939

XXXI

Page 28: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

CONTENTS

Remember—The Purpose of Design Is Communication 939

Understand Site Architecture and Content Strategy 939

Choose Fonts Wisely 939

Clearly Review the Requirements and Outline the Intended Functionality of Special Features 939

Design for the Entire User Experience 940

HTML5 in Drupal 940

How You Can Get Involved 940

Appendix E: Accessibility 941

Recent Enhancements 941

What Are the Standards? 942

Who Benefits? 942

It's the Law 943

Nine Ways to Make Your Site Accessible 943

Accessible Modules 943

Theming Your Site 944

Contrast and Color 944

Automated Testing 944

Simulation 945

Bring in WAI-ARIA 945

Maintenance is Critical 945

Schedule Regular Reviews of New and Old Pages 946

Get Expert Feedback 946

Appendix F: Windows Development Environment 947

LAMP to WISP 947

Visual Studio 948

WAMP Stack 948

Drupal Bits 953

VS.Php 957

phpMyAdmin and MySQL Connector 963

Drush 965

xxxii

Page 29: The definitive guide to Drupal 7 : [everything you need to ... Contents ata Glance iv Foreword xxxiv Aboutthe Authors xxxv Aboutthe Technical Reviewer..... xli Acknowledgments xlii

II CONTENTS

Installing Drush for Windows 965

Running Drush 968

Summary 969

Appendix G: Installing Drupal on Ubuntu 971

Running Ubuntu on Windows or Mac OS X 971

Customizing Ubuntu for Drupal Development with Drubuntu 972

Installing Drupal 973

Appendix H: Mac OSX Installation 977

Downloading Drupal Core File 979

Appendix I: Setting Up a Drupal Environment with the Acquia Dev Desktop 985

Installation 986

Taking It Further 987

Index: 991

xxxiii