135

Building and Theming Drupal Collection - Pearsoncmg.com

Embed Size (px)

Citation preview

Building andTheming Drupal

Collection

Upper Saddle River, NJ • Boston • Indianapolis • San FranciscoNew York • Toronto • Montreal • London • Munich • Paris • Madrid

Cape Town • Sydney • Tokyo • Singapore • Mexico City

Note from the PublisherThe Building and Theming Drupal Collection includes two popular eBooks:

• Front End Drupal: Designing,Theming, Scripting, by Emma Jane Hogbin andKonstantin Käfer

• Drupal’s Building Blocks, by Earl Miles and Lynette Miles

With Drupal,Web professionals can create full-featured Web sites with just a few clicks.Drupal’s core is compact and well documented, but much of Drupal’s immense powerlies elsewhere—in external modules.This collection brings together two eBooks thatprovide an in-depth guide to customizing Drupal 6 Web sites with front end tips andtricks and detailed information about the most powerful site building modules: CCK,Views, and Panels.This eBook collection includes several step-by-step case studies show-ing how to build and customize sites from scratch.This collection will help you createmore powerful, flexible, and manageable Web sites—whether you’re a Web developer,designer, administrator, architect, or consultant.

To simplify access, we’ve appended “A” to the pages of Front End Drupal and “B” to thepages of Drupal’s Building Blocks.This enabled us to produce a single, comprehensive tableof contents and dedicated indexes so that you can easily link to the topics you want.

We hope you find this collection useful!

—The editorial and production teams at Addison-Wesley Professional and Prentice Hall

Many of the designations used by manufacturers and sellers to distinguish their productsare claimed as trademarks.Where those designations appear in this book, and the pub-lisher was aware of a trademark claim, the designations have been printed with initialcapital letters or in all capitals.

The authors and publisher have taken care in the preparation of this book, but make noexpressed or implied warranty of any kind and assume no responsibility for errors oromissions. No liability is assumed for incidental or consequential damages in connectionwith or arising out of the use of the information or programs contained herein.

The publisher offers excellent discounts on this book when ordered in quantity for bulkpurchases or special sales, which may include electronic versions and/or custom coversand content particular to your business, training goals, marketing focus, and brandinginterests. For more information, please contact:

U.S. Corporate and Government Sales(800) [email protected]

For sales outside the United States, please contact:

International [email protected]

Visit us on the Web: informit.com/ph

Copyright © 2012 Pearson Education, Inc.

All rights reserved. Printed in the United States of America.This publication is protectedby copyright, and permission must be obtained from the publisher prior to any prohibit-ed reproduction, storage in a retrieval system, or transmission in any form or by anymeans, electronic, mechanical, photocopying, recording, or likewise.To obtain permissionto use material from this work, please submit a written request to Pearson Education,Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458,or you may fax your request to (201) 236-3290.

ISBN-13: 978-0-13-297924-5ISBN-10: 0-13-297924-1

Table of Contents

FRONT END DRUPAL

1 Web Page Design . . . . . . . . . . . . . . . . . . . . . . .1ADescribing Content . . . . . . . . . . . . . . . . . . . . . . . . .2A

Displaying Content . . . . . . . . . . . . . . . . . . . . . . .3A

Content Types and Content Fields . . . . . . . . . . . .5A

Organizing Lists of Content . . . . . . . . . . . . . . . . . . .8A

Chronological Organization . . . . . . . . . . . . . . . . .9A

Linear Organization . . . . . . . . . . . . . . . . . . . . .10A

Topical Organization . . . . . . . . . . . . . . . . . . . . .10A

Popularity-Based Organization . . . . . . . . . . . . . .12A

Task-Based Organization . . . . . . . . . . . . . . . . . .13A

Page Design and Layout . . . . . . . . . . . . . . . . . . . .14A

Interface Components . . . . . . . . . . . . . . . . . . .14A

Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15A

Design Resources . . . . . . . . . . . . . . . . . . . . . .17A

Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20A

User Satisfaction . . . . . . . . . . . . . . . . . . . . . . .21A

Guided Tasks . . . . . . . . . . . . . . . . . . . . . . . . . .22A

Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22A

Separating Form, Function, and Behavior . . . . . .23A

XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23A

Cascading Style Sheets . . . . . . . . . . . . . . . . . .24A

Scripting Languages . . . . . . . . . . . . . . . . . . . . .24A

Interaction with JavaScript . . . . . . . . . . . . . . . .24A

Work Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25A

Working with Designers . . . . . . . . . . . . . . . . . .26A

Working with Programmers . . . . . . . . . . . . . . . .27A

Working with Clients . . . . . . . . . . . . . . . . . . . . .27A

Working with Site Visitors . . . . . . . . . . . . . . . . .28A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29A

2 The Themers’ Toolkit . . . . . . . . . . . . . . . . . . . .31AA Gentle Introduction . . . . . . . . . . . . . . . . . . . . . .32A

Building a Page for Display . . . . . . . . . . . . . . . .32A

Directory Structure . . . . . . . . . . . . . . . . . . . . . .33A

Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33A

Theming Strategies . . . . . . . . . . . . . . . . . . . . . . . .33A

Best Practices . . . . . . . . . . . . . . . . . . . . . . . . .34A

Alternative Strategies . . . . . . . . . . . . . . . . . . . .34A

Drupal Terminology . . . . . . . . . . . . . . . . . . . . . . . .36A

Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36A

Users, Roles, and Permissions . . . . . . . . . . . . .36A

Blocks and Regions . . . . . . . . . . . . . . . . . . . . .37A

Categories, Taxonomy, Vocabularies, and Terms .38A

Parent Items and Weight . . . . . . . . . . . . . . . . .40A

Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40A

Pagers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41A

Hooks and Naming Conventions . . . . . . . . . . . .41A

Must-Have Modules . . . . . . . . . . . . . . . . . . . . . . .42A

Content Construction Kit (CCK) Module . . . . . . .42A

Views Module . . . . . . . . . . . . . . . . . . . . . . . . .53A

Devel Module . . . . . . . . . . . . . . . . . . . . . . . . . .57A

Browser Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . .60A

Firebug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60A

Web Developer’s Toolbar . . . . . . . . . . . . . . . . . .62A

Screen Shot and Testing Services . . . . . . . . . . .62A

Language References . . . . . . . . . . . . . . . . . . . . . .65A

XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66A

CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66A

PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68A

JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . .69A

Maintaining Your System . . . . . . . . . . . . . . . . . . . .69A

Scheduling Tasks with Cron . . . . . . . . . . . . . . .70A

Revision Control . . . . . . . . . . . . . . . . . . . . . . . .70A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71A

vi Contents

3 Working with Drupal Themes . . . . . . . . . . . . . .73AFinding Themes . . . . . . . . . . . . . . . . . . . . . . . . . .74A

Interface Components . . . . . . . . . . . . . . . . . . .76A

Develop a Library of Themes . . . . . . . . . . . . . . .77A

Installing Drupal Themes . . . . . . . . . . . . . . . . . . .78A

Download and Unpack . . . . . . . . . . . . . . . . . . .78A

Enable the New Theme . . . . . . . . . . . . . . . . . . .79A

Personal Themes . . . . . . . . . . . . . . . . . . . . . . .81A

Administering Themes . . . . . . . . . . . . . . . . . . . . . .82A

Global Settings . . . . . . . . . . . . . . . . . . . . . . . .83A

Theme-Specific Settings . . . . . . . . . . . . . . . . . .84A

The Front Page . . . . . . . . . . . . . . . . . . . . . . . . .85A

Anatomy of a Theme . . . . . . . . . . . . . . . . . . . . . . .88A

Naming and Initializing the Theme . . . . . . . . . . .88A

Page Template . . . . . . . . . . . . . . . . . . . . . . . . .89A

Including External CSS and JavaScript Files . . . .91A

Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92A

Screenshot . . . . . . . . . . . . . . . . . . . . . . . . . . .93A

Starter Themes . . . . . . . . . . . . . . . . . . . . . . . . . .94A

Zen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95A

Custom Theme Settings . . . . . . . . . . . . . . . . . .97A

Customizing Banner Images . . . . . . . . . . . . . . .97A

Migrating to Drupal 6 . . . . . . . . . . . . . . . . . . . . . .99A

Converting a Drupal 5.x Theme to a Drupal 6.x Theme . . . . . . . . . . . . . . . . . . . . .100A

WordPress . . . . . . . . . . . . . . . . . . . . . . . . . . .101A

Joomla! . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104A

4 The Drupal Page . . . . . . . . . . . . . . . . . . . . . .107AElements of a Page . . . . . . . . . . . . . . . . . . . . . .107A

Dissecting a Theme . . . . . . . . . . . . . . . . . . . .108A

Sitewide Page Variables . . . . . . . . . . . . . . . . . . .109A

General Utility Variables . . . . . . . . . . . . . . . . .111A

Page Metadata . . . . . . . . . . . . . . . . . . . . . . .111A

Site Identity . . . . . . . . . . . . . . . . . . . . . . . . . .112A

viiContents

Page Content, Drupal Messages, and Help Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112A

Creating New Page Variables . . . . . . . . . . . . . .113A

Modifying Page Variables . . . . . . . . . . . . . . . .115A

Navigation and Menus . . . . . . . . . . . . . . . . . . . .115A

Theming Menus . . . . . . . . . . . . . . . . . . . . . . .118A

Grid Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .120A

Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .121A

Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124A

Customizing the Markup of Blocks . . . . . . . . .125A

Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126A

Changing Templates . . . . . . . . . . . . . . . . . . . . . .128A

Custom Front Page . . . . . . . . . . . . . . . . . . . . .129A

Custom Offline Page . . . . . . . . . . . . . . . . . . . .130A

Alias: Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133A

New Templates from Aliased URLs . . . . . . . . .134A

Page Templates for Views . . . . . . . . . . . . . . .136A

Adding CSS Classes . . . . . . . . . . . . . . . . . . . .136A

Page Templates for Content Types . . . . . . . . . .137A

Taxonomy Templates . . . . . . . . . . . . . . . . . . . . . .138A

Graphical Headers . . . . . . . . . . . . . . . . . . . . .140A

Delivering Plain Content . . . . . . . . . . . . . . . . . . .141A

Print-Friendly Pages . . . . . . . . . . . . . . . . . . . .142A

Mobile Devices . . . . . . . . . . . . . . . . . . . . . . .147A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . .149A

5 Drupal Content . . . . . . . . . . . . . . . . . . . . . . .151ANode Templates . . . . . . . . . . . . . . . . . . . . . . . . .151A

The Template File node.tpl.php . . . . . . . . . . . .154A

Gaining More Control Than $content Provides . . .155A

Deciphering the Object $node . . . . . . . . . . . . .155A

Accessing Content in the $node Object . . . . . .158A

Sanitized Data Is More Secure . . . . . . . . . . . .160A

Node Template Variables . . . . . . . . . . . . . . . . . . .161A

Creating New Variables . . . . . . . . . . . . . . . . . .161A

Changing the Defaults . . . . . . . . . . . . . . . . . .163A

Node Links . . . . . . . . . . . . . . . . . . . . . . . . . .163A

viii Contents

Pages and Teasers . . . . . . . . . . . . . . . . . . . . . . .165A

Administrative Control of the Default Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . .165A

A Teaser Is Not a Summary . . . . . . . . . . . . . .166A

Templates for Teasers . . . . . . . . . . . . . . . . . .168A

Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169A

Choosing Your Visuals . . . . . . . . . . . . . . . . . .170A

Images Hosted Offsite . . . . . . . . . . . . . . . . . .172A

Image Module . . . . . . . . . . . . . . . . . . . . . . . .173A

CCK Images: ImageField and Image Cache . . .176A

Making Lists of Content with Views . . . . . . . . . . .177A

Template Files . . . . . . . . . . . . . . . . . . . . . . . .177A

New Variables, with Preprocess Functions . . . .179A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .181A

6 Customizing the Content-Editing Forms . . . . .183AWeb Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184A

Form Candy . . . . . . . . . . . . . . . . . . . . . . . . . . . .185A

Working with Style Sheets . . . . . . . . . . . . . . .185A

Coloring in Required Fields . . . . . . . . . . . . . .186A

Focus on Input . . . . . . . . . . . . . . . . . . . . . . . .187A

Background Images on Form Fieldsets . . . . . .188A

Advanced CSS Selectors . . . . . . . . . . . . . . . .191A

Vertical Tabs . . . . . . . . . . . . . . . . . . . . . . . . .192A

Node Form and Usability Improvements . . . . . .193A

Rich Text Editing . . . . . . . . . . . . . . . . . . . . . . . . .195A

Installing TinyMCE . . . . . . . . . . . . . . . . . . . . .195A

Configuring TinyMCE . . . . . . . . . . . . . . . . . . .196A

Image Integration . . . . . . . . . . . . . . . . . . . . . .199A

Extending TinyMCE . . . . . . . . . . . . . . . . . . . .201A

Altering Forms with FAPI . . . . . . . . . . . . . . . . . . .201A

Changing Forms Throughout Your Site . . . . . . .202A

Changing Specific Forms . . . . . . . . . . . . . . . .205A

Changing Display Text in Forms . . . . . . . . . . . .206A

Removing Fields from the Form . . . . . . . . . . .207A

Changing Form Widgets . . . . . . . . . . . . . . . . .209A

ixContents

Multiple-Page Forms . . . . . . . . . . . . . . . . . . . . . .210A

Webform . . . . . . . . . . . . . . . . . . . . . . . . . . . .211A

Altering Flow . . . . . . . . . . . . . . . . . . . . . . . . .211A

Improving Access to Edit Screens . . . . . . . . . . . .212A

Admin Links . . . . . . . . . . . . . . . . . . . . . . . . . .212A

Editing Blocks . . . . . . . . . . . . . . . . . . . . . . . .213A

Preprocess Functions . . . . . . . . . . . . . . . . . . .214A

Structure of the preprocess_block Function . . .215A

Adding Block-Editing Capabilities to a Theme . .216A

Administrative Interfaces . . . . . . . . . . . . . . . .217A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .217A

7 Users and Community Participation . . . . . . . .219AUsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .219A

User Profiles . . . . . . . . . . . . . . . . . . . . . . . . .220A

Theming the Default Profile . . . . . . . . . . . . . . .222A

Adding More Content . . . . . . . . . . . . . . . . . . .225A

Granting and Restricting Access . . . . . . . . . . . . .227A

Defining Roles . . . . . . . . . . . . . . . . . . . . . . . .227A

Granting and Revoking Permissions . . . . . . . . .228A

Checking Access at the Theme Level . . . . . . . .229A

Extending the Administrative Role to More Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .231A

Community Comments . . . . . . . . . . . . . . . . . . . .231A

Customizing Comment Display . . . . . . . . . . . .231A

Adding User Identity to Comments . . . . . . . . .234A

Disqus . . . . . . . . . . . . . . . . . . . . . . . . . . . . .234A

User-Generated Content . . . . . . . . . . . . . . . . . . .235A

Blogs (and Comments) . . . . . . . . . . . . . . . . . .235A

Forums . . . . . . . . . . . . . . . . . . . . . . . . . . . . .236A

Wikis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .237A

Recipes and Specialized Content . . . . . . . . . .239A

Spam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .240A

CAPTCHA . . . . . . . . . . . . . . . . . . . . . . . . . . . .241A

Comment Closer . . . . . . . . . . . . . . . . . . . . . .242A

Spam Filtering Services . . . . . . . . . . . . . . . . .243A

x Contents

Private Web Site Areas . . . . . . . . . . . . . . . . . . . .244A

Member-Only Sites . . . . . . . . . . . . . . . . . . . . .244A

Private Content Fields . . . . . . . . . . . . . . . . . .247A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248A

8 Administrative Interfaces . . . . . . . . . . . . . . . .251ACreating a Custom Administrative Interface . . . . .252A

Applying a Separate Administrative Theme . . . .252A

RootCandy . . . . . . . . . . . . . . . . . . . . . . . . . . .253A

Task-Based Navigation . . . . . . . . . . . . . . . . . . . .256A

Creating Custom Menus . . . . . . . . . . . . . . . . .257A

Deploying Custom Menus . . . . . . . . . . . . . . . .259A

Administrative Menus . . . . . . . . . . . . . . . . . . . . .261A

Admin Menu . . . . . . . . . . . . . . . . . . . . . . . . .261A

Teleport . . . . . . . . . . . . . . . . . . . . . . . . . . . . .263A

Navigate . . . . . . . . . . . . . . . . . . . . . . . . . . . .264A

Administrative Dashboards and Control Panels . . .266A

Control Panel . . . . . . . . . . . . . . . . . . . . . . . . .266A

Theming Control Panel . . . . . . . . . . . . . . . . . .268A

Custom Administrative Screens . . . . . . . . . . . . . .270A

New Content View . . . . . . . . . . . . . . . . . . . . .271A

Orphan Images View . . . . . . . . . . . . . . . . . . .274A

Unpublished Content by Category . . . . . . . . . .278A

Error! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .279A

Error Messages . . . . . . . . . . . . . . . . . . . . . . .279A

404, Page Not Found . . . . . . . . . . . . . . . . . . .280A

Custom Error . . . . . . . . . . . . . . . . . . . . . . . . .281A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . .283A

9 Learning JavaScript . . . . . . . . . . . . . . . . . . . .285AJavaScript versus DOM . . . . . . . . . . . . . . . . . . . .286A

The JavaScript Language . . . . . . . . . . . . . . . . . . .287A

First Steps: Executing Code . . . . . . . . . . . . . .287A

Declaring Variables . . . . . . . . . . . . . . . . . . . . .288A

Controlling the Flow . . . . . . . . . . . . . . . . . . . .292A

Object Orientation in JavaScript . . . . . . . . . . . . . .293A

The “Everything Is an Object” Approach . . . . . .293A

Defining and Working with Objects . . . . . . . . . .296A

xiContents

Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . .298A

Using Functions . . . . . . . . . . . . . . . . . . . . . . .302A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .309A

10 An Introduction to jQuery . . . . . . . . . . . . . . .311AA First Look at jQuery . . . . . . . . . . . . . . . . . . . . .313A

Setting Up jQuery . . . . . . . . . . . . . . . . . . . . . .313A

Executing Code on Page Load . . . . . . . . . . . . .314A

Navigating the DOM Tree . . . . . . . . . . . . . . . .318A

Using jQuery . . . . . . . . . . . . . . . . . . . . . . . . . . .320A

Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .321A

Setting and Retrieving Attributes . . . . . . . . . . .326A

Finding Elements . . . . . . . . . . . . . . . . . . . . . .329A

Inserting, Moving, and Removing Elements . . .330A

Leveraging jQuery’s Full Potential . . . . . . . . . . . . .333A

Animations . . . . . . . . . . . . . . . . . . . . . . . . . .333A

Using jQuery Helper Functions . . . . . . . . . . . .336A

Calling the Server with XmlHttpRequest . . . . . .337A

Plugins for jQuery . . . . . . . . . . . . . . . . . . . . . .342A

jQuery UI . . . . . . . . . . . . . . . . . . . . . . . . . . . .343A

Using Other JavaScript Libraries . . . . . . . . . . . . .343A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .344A

11 JavaScript in Drupal . . . . . . . . . . . . . . . . . . .345AServer-Side Drupal Integration . . . . . . . . . . . . . . .345A

Adding JavaScript to a Page . . . . . . . . . . . . . .346A

Creating Menu Callback Handlers . . . . . . . . . .349A

Creating JSON . . . . . . . . . . . . . . . . . . . . . . . .351A

Architecting a Component . . . . . . . . . . . . . . . . . .353A

Example: Horizontal Scroller . . . . . . . . . . . . . . . .355A

The Component Skeleton . . . . . . . . . . . . . . . .356A

Creating the Markup . . . . . . . . . . . . . . . . . . . .357A

Drupal’s JavaScript Behaviors . . . . . . . . . . . . .357A

Filling the Component with Functionality . . . . .361A

Making the Component Data-Source Agnostic . . . . . . . . . . . . . . . . . . . . . . . . . . . .374A

Integration with Drupal . . . . . . . . . . . . . . . . . .377A

xii Contents

Using Plugins and jQuery UI . . . . . . . . . . . . . . . .377A

Sparklines . . . . . . . . . . . . . . . . . . . . . . . . . . .377A

jQuery Drupal Modules . . . . . . . . . . . . . . . . . .379A

jQuery UI . . . . . . . . . . . . . . . . . . . . . . . . . . . .379A

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .380A

A Installing Drupal . . . . . . . . . . . . . . . . . . . . . .381ASetting Up a Development Server . . . . . . . . . . . .381A

Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . .382A

Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .382A

Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . .382A

Configuring Document Root and Virtual Hosts . . .383A

Installing Drupal—and Common Hurdles to Its Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385A

A Quick Glance at the Admin Area . . . . . . . . . . . .388A

Installing Modules . . . . . . . . . . . . . . . . . . . . . . .389A

B Supplemental Code . . . . . . . . . . . . . . . . . . . .391Atemplate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .391A

index.html . . . . . . . . . . . . . . . . . . . . . . . . . . .391A

index-input.html . . . . . . . . . . . . . . . . . . . . . . .396A

demo-module . . . . . . . . . . . . . . . . . . . . . . . . . . .397A

demo.module . . . . . . . . . . . . . . . . . . . . . . . . .397A

demo.info . . . . . . . . . . . . . . . . . . . . . . . . . . .399A

template-skeleton . . . . . . . . . . . . . . . . . . . . . . . .400A

skeleton.js . . . . . . . . . . . . . . . . . . . . . . . . . . .400A

skeleton.html . . . . . . . . . . . . . . . . . . . . . . . . .402A

skeleton.css . . . . . . . . . . . . . . . . . . . . . . . . .403A

horizscroll and horizscroll-datasource . . . . . . . . . .404A

horizscroll.js . . . . . . . . . . . . . . . . . . . . . . . . .404A

horizscroll.html . . . . . . . . . . . . . . . . . . . . . . .410A

horizscroll.css . . . . . . . . . . . . . . . . . . . . . . . .413A

sparkline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .415A

sparkline.html . . . . . . . . . . . . . . . . . . . . . . . .415A

sparkline.js . . . . . . . . . . . . . . . . . . . . . . . . . .417A

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .419A

xiiiContents

DRUPAL’S BUILDING BLOCKS

I: Content Construction Kit

1 Introducing CCK and Nodes . . . . . . . . . . . . . . . 3BThe Node System . . . . . . . . . . . . . . . . . . . . . . . . . 3B

Why Nodes Are Important . . . . . . . . . . . . . . . . . 4B

Default Content Types . . . . . . . . . . . . . . . . . . . . 4B

Parts of a Node . . . . . . . . . . . . . . . . . . . . . . . . 5B

Why Add Fields to Nodes? . . . . . . . . . . . . . . . . . 7B

Quest for the Grail: How CCK Was Born . . . . . . . . . 8B

Getting Started with CCK . . . . . . . . . . . . . . . . . . . 10B

Creating a New Content Type . . . . . . . . . . . . . . . . 11B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15B

2 Field Concepts . . . . . . . . . . . . . . . . . . . . . . . . 17BWhat You Should Know Before Creating Fields and Content Types . . . . . . . . . . . . . . . . . . . . . . . . 17B

The Content Type Pages . . . . . . . . . . . . . . . . . . . . 17B

Identification . . . . . . . . . . . . . . . . . . . . . . . . . 18B

Submission Form Settings . . . . . . . . . . . . . . . . 19B

Workflow Settings . . . . . . . . . . . . . . . . . . . . . . 21B

Comment Settings . . . . . . . . . . . . . . . . . . . . . 22B

Fields, Export, and Import . . . . . . . . . . . . . . . . 22B

Creating New Fields for Content . . . . . . . . . . . . . . 24B

Adding Fields . . . . . . . . . . . . . . . . . . . . . . . . . 24B

Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 26B

Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29B

Putting the Parts Together . . . . . . . . . . . . . . . . . . 30B

Changing the Field Display . . . . . . . . . . . . . . . 33B

Sharing Fields . . . . . . . . . . . . . . . . . . . . . . . . 36B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38B

3 Deeper into Fields . . . . . . . . . . . . . . . . . . . . . 39BChoosing Field Types . . . . . . . . . . . . . . . . . . . . . . 39B

Using Text . . . . . . . . . . . . . . . . . . . . . . . . . . . 40B

Using Numeric Types . . . . . . . . . . . . . . . . . . . . 40B

xiv Contents

Using Node Reference . . . . . . . . . . . . . . . . . . 41B

User Reference . . . . . . . . . . . . . . . . . . . . . . . . 42B

Constraining Data with Widgets . . . . . . . . . . . . . . 43B

Date Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48B

Computed Fields . . . . . . . . . . . . . . . . . . . . . . . . . 51B

Link and Email Fields . . . . . . . . . . . . . . . . . . . . . 54B

Highly Visual Media . . . . . . . . . . . . . . . . . . . . . . . 55B

FileField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55B

ImageField . . . . . . . . . . . . . . . . . . . . . . . . . . . 56B

ImageAPI, ImageCache, and ImageCache UI . . . 56B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57B

4 Themes and CCK . . . . . . . . . . . . . . . . . . . . . . 59BTheme Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 59B

CCK Specific Theming . . . . . . . . . . . . . . . . . . . . . 62B

Formatters . . . . . . . . . . . . . . . . . . . . . . . . . . . 62B

Field Templates . . . . . . . . . . . . . . . . . . . . . . . 62B

Node Templates . . . . . . . . . . . . . . . . . . . . . . . 65B

Excluding Fields . . . . . . . . . . . . . . . . . . . . . . . 68B

Node Reference . . . . . . . . . . . . . . . . . . . . . . . 68B

Helper Modules . . . . . . . . . . . . . . . . . . . . . . . . . . 69B

Theme Developer . . . . . . . . . . . . . . . . . . . . . . 70B

Contemplate . . . . . . . . . . . . . . . . . . . . . . . . . . 71B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73B

5 CCK API . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75BUsing the CCK API . . . . . . . . . . . . . . . . . . . . . . . . 75B

The Field Model . . . . . . . . . . . . . . . . . . . . . . . . . 76B

Creating New Field Types, Widget Types, andFormatters . . . . . . . . . . . . . . . . . . . . . . . . . . . 76B

Creating Custom Field Types, Widget Types, orFormatters . . . . . . . . . . . . . . . . . . . . . . . . . . . 77B

Field Type Modules . . . . . . . . . . . . . . . . . . . . . 79B

Widget Type Modules . . . . . . . . . . . . . . . . . . . . . . 85B

Formatter Modules . . . . . . . . . . . . . . . . . . . . . . . 87B

Creating Field Instances Using Content Copy . . . . 91B

Creating Field Instances with the CRUD API . . . . . 91B

xvContents

Creating Data for CCK Fields . . . . . . . . . . . . . . . . 95B

Miscellaneous Helper Functions . . . . . . . . . . . . . . 97B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98B

II: Views

6 Relational Databases . . . . . . . . . . . . . . . . . . 101BDrupal, SQL, and the Emergence of Views . . . . . 101B

Pronouncing SQL . . . . . . . . . . . . . . . . . . . . . 101B

The Drupal “Learning Cliff” . . . . . . . . . . . . . . 102B

The Basics of Relational Databases . . . . . . . . . . 102B

Rows and Fields . . . . . . . . . . . . . . . . . . . . . . 103B

Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103B

Filtering and Sorting . . . . . . . . . . . . . . . . . . . . . 105B

Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105B

Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106B

Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106B

From SQL to Views to Human Language . . . . . . . 107B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108B

7 Creating Views . . . . . . . . . . . . . . . . . . . . . . 109BViews UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109B

List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110B

Add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112B

Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125B

Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125B

Showing Your Views to the World: Creating Displays . . . . . . . . . . . . . . . . . . . . . . . 131B

Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132B

Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133B

Attachments . . . . . . . . . . . . . . . . . . . . . . . . . 135B

Feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136B

xvi Contents

8 Arguments, Exposed Filters, and Relationships . . . . . . . . . . . . . . . . . . . . . . . . 137BArguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137B

Arguments as Filters . . . . . . . . . . . . . . . . . . . 138B

Configuring an Argument . . . . . . . . . . . . . . . . 139B

Using Arguments as Part of a View . . . . . . . . 142B

Exposed Filters . . . . . . . . . . . . . . . . . . . . . . . . . 145B

Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . 148B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151B

9 Theming Views . . . . . . . . . . . . . . . . . . . . . . . 153BAn Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 153B

Classes in Views . . . . . . . . . . . . . . . . . . . . . . . . 153B

Template Files . . . . . . . . . . . . . . . . . . . . . . . . . . 156B

The Display Templates . . . . . . . . . . . . . . . . . 159B

View Styles . . . . . . . . . . . . . . . . . . . . . . . . . 160B

The Row Templates . . . . . . . . . . . . . . . . . . . . 161B

Other Templates . . . . . . . . . . . . . . . . . . . . . . 162B

Working with Templates . . . . . . . . . . . . . . . . . . . 164B

Rescan the Template Files . . . . . . . . . . . . . . 165B

Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 167B

Printing Default Messages for Empty Fields . . . . . . . . . . . . . . . . . . . . . . . . . 167B

Grouping in a Template . . . . . . . . . . . . . . . . . 169B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175B

10 Query Optimization . . . . . . . . . . . . . . . . . . . . 177BBalancing Development Time Against CPU Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177B

Sticking with What Views Gives You . . . . . . . . . . 177B

When You Need More Than Views . . . . . . . . . . . 178B

Determining Query Performance . . . . . . . . . . . 178B

Embedding Queries . . . . . . . . . . . . . . . . . . . . 179B

EXPLAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180B

Indexing Versus Caching . . . . . . . . . . . . . . . . 182B

Experimenting with Your Site . . . . . . . . . . . . . . . 183B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183B

xviiContents

11 Views API . . . . . . . . . . . . . . . . . . . . . . . . . . 185BData Architecture . . . . . . . . . . . . . . . . . . . . . . . 185B

Object-Oriented Programming . . . . . . . . . . . . . 186B

Base Tables and Relationships . . . . . . . . . . . 191B

The Objects Involved in a View . . . . . . . . . . . . 192B

The Views API . . . . . . . . . . . . . . . . . . . . . . . . . . 199B

The Life Cycle of a View . . . . . . . . . . . . . . . . . . . 201B

View Execution Cycle . . . . . . . . . . . . . . . . . . . 201B

Executing a Views Display . . . . . . . . . . . . . . . 203B

Execution-Related Hooks . . . . . . . . . . . . . . . . 204B

The Database Schema and Data Hook . . . . . . . . 206B

Relating Tables to Each Other . . . . . . . . . . . . 206B

Declaring Tables in hook_views_data() . . . . . . 207B

Declaring Fields on Tables . . . . . . . . . . . . . . . 209B

Handlers Versus Plugins . . . . . . . . . . . . . . . . . . 210B

Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . 210B

Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213B

III: Panels

12 Introducing Panels . . . . . . . . . . . . . . . . . . . . 217BIntroduction to Panels . . . . . . . . . . . . . . . . . . . . 217B

A Brief History of Panels . . . . . . . . . . . . . . . . 217B

Push and Pull: How Panels Is Different . . . . . . 218B

Point-and-Click Layout . . . . . . . . . . . . . . . . . . 219B

Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221B

Pluggable Architecture . . . . . . . . . . . . . . . . . . 221B

Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222B

Panels Package . . . . . . . . . . . . . . . . . . . . . . 222B

Chaos Tool Suite . . . . . . . . . . . . . . . . . . . . . 223B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224B

13 Creating Panels . . . . . . . . . . . . . . . . . . . . . . 225BYour First Panel . . . . . . . . . . . . . . . . . . . . . . . . . 225B

The Panels Dashboard . . . . . . . . . . . . . . . . . 226B

Panel Pages . . . . . . . . . . . . . . . . . . . . . . . . . 227B

xviii Contents

Panel Nodes . . . . . . . . . . . . . . . . . . . . . . . . . 233B

Mini-Panels . . . . . . . . . . . . . . . . . . . . . . . . . . 236B

Adding Content to Panels . . . . . . . . . . . . . . . . . . 237B

Adding Content Panes . . . . . . . . . . . . . . . . . . 238B

Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242B

Configuring Existing Content Panes . . . . . . . . 243B

Access Rules . . . . . . . . . . . . . . . . . . . . . . . . . . 244B

Overriding Core Display Pages . . . . . . . . . . . . . . 246B

Node View . . . . . . . . . . . . . . . . . . . . . . . . . . 248B

Taxonomy . . . . . . . . . . . . . . . . . . . . . . . . . . . 251B

User View . . . . . . . . . . . . . . . . . . . . . . . . . . . 252B

Overriding Core Node Editing Pages . . . . . . . . . . 253B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255B

14 Contexts, Relationships, and Arguments in Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . 257BContexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257B

Contexts in Panel Pages . . . . . . . . . . . . . . . . 258B

Taxonomy . . . . . . . . . . . . . . . . . . . . . . . . . . . 262B

Arguments in Panes . . . . . . . . . . . . . . . . . . . . . 264B

The Add Content Modal for Views . . . . . . . . . 266B

View Pane Displays . . . . . . . . . . . . . . . . . . . . 268B

Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . 271B

Using Relationships . . . . . . . . . . . . . . . . . . . 271B

User Reference and Node Reference . . . . . . . 272B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274B

15 Panels Theming . . . . . . . . . . . . . . . . . . . . . . 275BLayout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275B

Flexible Layout . . . . . . . . . . . . . . . . . . . . . . . 275B

Changing Layouts . . . . . . . . . . . . . . . . . . . . . 279B

Stylizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280B

Working with Styles . . . . . . . . . . . . . . . . . . . . 282B

CSS in the Panels UI . . . . . . . . . . . . . . . . . . . . . 284B

CSS in Source Code . . . . . . . . . . . . . . . . . . . . . 285B

Identifying a Particular Pane . . . . . . . . . . . . . 286B

Other Stylistic Changes . . . . . . . . . . . . . . . . . 289B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290B

xixContents

16 Site Deployment . . . . . . . . . . . . . . . . . . . . . 291BConfiguring Your Development Environment . . . . . 291B

Content Versus Structure . . . . . . . . . . . . . . . 291B

Source Control . . . . . . . . . . . . . . . . . . . . . . . 292B

Moving to Production . . . . . . . . . . . . . . . . . . . . . 293B

Keeping Development Separate from Production . . . . . . . . . . . . . . . . . . . . . . . . . . 293B

Testing Your Changes . . . . . . . . . . . . . . . . . . 293B

Documenting Your Work . . . . . . . . . . . . . . . . 294B

Exporting Your Structures . . . . . . . . . . . . . . . . . . 294B

Exporting CCK . . . . . . . . . . . . . . . . . . . . . . . 295B

Exporting Views . . . . . . . . . . . . . . . . . . . . . . 296B

Exporting Panels . . . . . . . . . . . . . . . . . . . . . . 298B

Helper Modules . . . . . . . . . . . . . . . . . . . . . . . . . 299B

Deploy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299B

Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299B

Drush . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299B

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300B

IV: Appendices

A Other Useful Modules . . . . . . . . . . . . . . . . . . 303BExtending the Use of Your Modules . . . . . . . . . . 303B

General Modules . . . . . . . . . . . . . . . . . . . . . . . . 303B

Pathauto . . . . . . . . . . . . . . . . . . . . . . . . . . . 303B

Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304B

Views_or . . . . . . . . . . . . . . . . . . . . . . . . . . . 304B

Nodequeue . . . . . . . . . . . . . . . . . . . . . . . . . . 304B

Flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305B

Views Slideshow . . . . . . . . . . . . . . . . . . . . . . 305B

Views Bonus Pack . . . . . . . . . . . . . . . . . . . . 305B

Views Attach . . . . . . . . . . . . . . . . . . . . . . . . 306B

Views Import . . . . . . . . . . . . . . . . . . . . . . . . 306B

ApacheSolr Views . . . . . . . . . . . . . . . . . . . . . 306B

SimpleViews . . . . . . . . . . . . . . . . . . . . . . . . . 307B

Views Bulk Operations . . . . . . . . . . . . . . . . . 307B

xx Contents

Views Datasource . . . . . . . . . . . . . . . . . . . . . 307B

Sheetnode . . . . . . . . . . . . . . . . . . . . . . . . . . 307B

CCK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307B

Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . 308B

Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308B

Advanced Profile Kit . . . . . . . . . . . . . . . . . . . 308B

Total Control Admin Dashboard . . . . . . . . . . . 308B

B Reporting Issues . . . . . . . . . . . . . . . . . . . . . 309BSubmit a Complete Report . . . . . . . . . . . . . . . . . 309B

Read the Documentation . . . . . . . . . . . . . . . . . . 310B

Check Other Sources . . . . . . . . . . . . . . . . . . . . . 311B

Know the Difference between a Bug and a Support Request . . . . . . . . . . . . . . . . . . . . . . . . 312B

Stay on Topic . . . . . . . . . . . . . . . . . . . . . . . . . . 312B

Understand the Life Cycle of a Bug . . . . . . . . . . 312B

Be Patient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313B

Remember That You’re Asking for Someone Else’s Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314B

Contribute Back . . . . . . . . . . . . . . . . . . . . . . . . 314B

C Views API Handlers and Plugins . . . . . . . . . . 315BViews Handlers . . . . . . . . . . . . . . . . . . . . . . . . . 315B

Field Handlers . . . . . . . . . . . . . . . . . . . . . . . 315B

Sort Handlers . . . . . . . . . . . . . . . . . . . . . . . . 316B

Filter Handlers . . . . . . . . . . . . . . . . . . . . . . . 316B

Handlers for Arguments . . . . . . . . . . . . . . . . 316B

Relationship Handlers . . . . . . . . . . . . . . . . . . 317B

Views Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . 317B

Display Plugins . . . . . . . . . . . . . . . . . . . . . . . 317B

Style Plugins . . . . . . . . . . . . . . . . . . . . . . . . 317B

Row Plugins . . . . . . . . . . . . . . . . . . . . . . . . . 318B

Views Classes . . . . . . . . . . . . . . . . . . . . . . . . . 318B

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327B

Upper Saddle River, NJ • Boston • Indianapolis • San FranciscoNew York • Toronto • Montreal • London • Munich • Paris • Madrid

Capetown • Sydney • Tokyo • Singapore • Mexico City

Front End DrupalDesigning, Theming, Scripting

Emma Jane Hogbin Konstantin Käfer

00_9780132979245_FM_A.indd i 1/6/12 9:47 AM

Praise for Front End Drupal

“Overall, a great book, jam-packed with lots of learning. Congrats to Emma and Konstantin for producing another great book in the Drupal library.”

—Addison Berry, documentation team lead for Drupal

“If you’re looking to create themes for the current version of Drupal, this is a good book to have.”

—Zoltan Hunt, editor, YYZtech.ca

“With its extensive coverage of all the key technologies and its wealth of valuable tips, Front End Drupal is an essential resource for learning how to create Drupal themes, and it fi lls a long-standing gap in the Drupal literature better than any other book currently available.”

—Michael J. Ross, Web developer, www.ross.ws

“Front End Drupal is a book the Drupal world has needed for years…”

—Jeff Eaton, Drupal core developer and coauthor of Using Drupal

“I can’t say enough good things about this book….If you are only going to buy two or three Drupal books, make sure this one is always handy while you are working.”

—Victor Kane, awebfactory.com.ar

00_9780132979245_FM_A.indd ii 1/6/12 9:47 AM

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.

The authors and publisher have taken care in the preparation of this book, but make no ex-pressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.

The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:

U.S. Corporate and Government Sales(800) [email protected]

For sales outside the United States please contact:

International [email protected]

Visit us on the Web: informit.com/ph

Library of Congress Cataloging-in-Publication Data

Hogbin, Emma Jane.

Front end Drupal : designing, theming, scripting / Emma Jane Hogbin and Konstantin Käfer.

p. cm.

Includes index.

ISBN 978-0-13-713669-8 (pbk. : alk. paper) 1. Drupal (Computer file) 2. Web sites-Design-Computer programs. 3. Web site development. I. Käfer, Konstantin. II. Title.

TK5105.8885.D78H65 2009

006.7’6—dc22

2009002636

Copyright © 2009 Pearson Education, Inc.

All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding per-missions, write to:

Pearson Education, IncRights and Contracts Department501 Boylston Street, Suite 900Boston, MA 02116Fax (617) 671-3447

ISBN-13: 978-0-13-713669-8ISBN-10: 0-13-713669-2 Text printed in the United States on recycled paper at R.R. Donnelley in Crawfordsville, IN.Second printing, June 2009

Editor-in-ChiefMark Taub

Executive EditorDebra Williams Cauley

Development EditorSonglin Qiu

Managing EditorJohn Fuller

Project EditorAnna Popick

Copy EditorJill Hobbs

IndexerMichael Loo

ProofreaderLinda Begley

Technical ReviewersKároly NégyesiBernie MonetteLynda ChiottiCaroline HillR.G. Daniel

Cover DesignerChuti Prasertsith

CompositionGloria Schurick

GraphicsTammy GrahamLaura Robbins

00_9780132979245_FM_A.indd iii 1/6/12 9:47 AM

iv

Foreword

At DrupalCon Barcelona in 2007, while giving my regular “State of Drupal” presenta-tion, I remarked that during my hour-long session, four new Drupal sites would be launched. I went on to suggest that three of those four sites would be ugly. A year later, at DrupalCon Szeged in Hungary, those four new sites per hour had grown to seven and Drupal 6 had been released, making it easier to create great-looking Web sites. Still, even now, Drupal faces a common problem on the Web—the relative lack of new, high quality themes.

Front End Drupal tackles that problem directly and is designed to help both ex-perienced designers and rank novices get an understanding of how Drupal theming works. From using contributed “starter themes,” to customizing templates to modify the markup used in Drupal’s output, to using jQuery and JavaScript to enhance the user experience, Front End Drupal clearly charts a path to theming mastery. In fact, I’ll be the fi rst to admit that I learned a lot from this book.

The Drupal community has created a remarkable platform that powers sites of all sizes and descriptions, all around the world. Together, we’ve crafted a robust, extensible content-management system that illustrates some of the key values in our community: fl exibility and utility, innovation and openness. But Drupal has always been a develop-er’s platform, even with the many designers in our ranks. It’s about time those designers had a great book. In fact, this book is valuable not just to the designers we have, but to the designers we want—the thousands who have never worked with Drupal.

The thing is that creating a Drupal theme isn’t always easy. It’s a crosscutting experi ence that requires a lot of diverse skills and utilizes expertise in XHTML, CSS, JavaScript, and PHP, all within the context of Drupal. Doing a Drupal theme right can be challenging, but it is also exciting and incredibly rewarding. A survey I con-ducted in 2008 listed “Finding skilled Drupal designers” as the number one entry on

00_9780132979245_FM_A.indd iv 1/6/12 9:47 AM

� v

the list of the “Top fi ve most diffi cult things,” as reported by both expert and novice users. We need to do more to fi nd new themers, as well as encourage and support the ones we already have.

I’m excited that Emma Jane and Konstantin recognized that and authored this book. It fi lls an important need in the Drupal ecosystem and will bring a new atten-tion to design in Drupal. Since I’ve mostly focused on the “back end,” it’s nice to see the “front end” get more and more attention. For Drupal to succeed, we need books like this. We need the skills it teaches and we need the people it attracts. We need the new themes those people will create and the new suggestions and improvements they bring to our project.

Dries BuytaertDrupal founder and project lead

v Foreword

00_9780132979245_FM_A.indd v 1/6/12 9:47 AM

vi

Preface

Drupal is an open-source content management system software package that is free to download, modify, and use. It has been implemented by thousands of people around the world and is used by millions of people daily as the basis for discussion Web sites, community portals, corporate intranets, e-commerce Web sites, vanity Web sites, resource directories, image galleries, podcasts, and more! By choosing to use Dru-pal, you are accessing not only an award-winning Web platform, but also its vibrant community.

This book will teach you how to customize how Drupal looks. Applying new de-signs is very easy—the code that controls how Drupal works is separated from the code that controls how Drupal looks. The design part of Drupal is referred to as the theme layer—and that’s what this book is all about. Individual designs are referred to as “themes” and the people who create and implement them are referred to as “themers.” By the time you reach the end of this book, you will have the tools to customize the experience for your content managers, Web site visitors, and Drupal administrators.

The book assumes you are familiar with how Drupal works and that you have been an administrator of a Drupal Web site. It would help if you are comfortable with Web site design and development, but these concepts will be explained for those who have only a limited experience with them. More specifi cally, this book will use code snippets written in HTML, CSS, PHP, and JavaScript.

Chapter 1

This chapter covers the basics of Web page design. It will help you to prepare your information so that it will slide easily into a Drupal Web site. You will learn how to de-scribe content and its organization; structure page layouts so that all of your interface components fi t sanely onto your Web pages; and implement a work fl ow that works for your Drupal team.

00_9780132979245_FM_A.indd vi 1/6/12 9:47 AM

Preface� vii

Chapter 2

With the basics of Web design under your belt, it is time to prepare your workstation for Drupal theming. In this chapter, you will learn about Drupal terminology and theming strategies as well as must-have modules and browser tools. Chapter 2 also in-cludes language references for each of the machine languages used in creating a Drupal theme.

Chapter 3

You will now move on to learning the basic anatomy of a Drupal theme. In Chapter 3, you will learn how to fi nd and install a premade Drupal theme. You will also learn the anatomy of a Drupal theme and discover how to use Starter Themes to reduce your development time. Tips are included on how to convert themes from WordPress, Joomla!, and Drupal 5.x.

Chapter 4

The overall structure of pages in Drupal is defi ned by the page template. In this chap-ter, you will learn how to customize every part of this template—from using sitewide page variables and menus, to changing page templates based on the section you are cur-rently in. Information on print-friendly templates and mobile devices is also included in this chapter.

Chapter 5

It’s time to get to the guts of your Web site—so in Chapter 5, you will learn how to cus-tomize your Web site content, including individual nodes and teaser summaries. This chapter also describes the most appropriate image module to use for your Web site. Ex-amples of output are provided to help you make the best decision for your content.

Chapter 6

The most commonly overlooked area in Drupal theme design is content editing forms. In this chapter, you will learn simple tips and tricks to make your forms more usable and will get a gentle introduction to altering forms with the Form API. Techniques described in this chapter will help you to enhance the usability of your content editing forms.

00_9780132979245_FM_A.indd vii 1/6/12 9:47 AM

viii Front End Drupal

Chapter 7

If you are running a community site, this chapter is a must—it includes information on how to theme user profi les, community comments, and user-generated content. Additional information is provided on creating private, member-only sections to your Web site.

Chapter 8

In this chapter, which covers administrative interfaces, you will learn how to make the administration of Drupal a little bit easier. Techniques include creating custom admin-istrative interfaces, adding task-based navigation, creating administrative menus, and customizing your Web site’s error messages.

Chapter 9

In this chapter, you will acquire the JavaScript skills required for writing truly stun-ning, portable, and fl exible components for your theme. Basic concepts or advanced object orientation—there’s certainly something you’ll learn in this chapter.

Chapter 10

An introduction to jQuery, the JavaScript library that ships with Drupal, will bring you up to speed with today’s most prevalent JavaScript library. You’ll also learn how jQuery is used in Drupal, how you can create stunning animations, and how you can implement AJAX callbacks to the server.

Chapter 11

In this chapter, you will learn how to apply your newfound JavaScript and jQuery knowledge to a Drupal Web site. By creating a horizontal scroller component, you’ll learn step by step how to architect a highly fl exible and reusable JavaScript widget. Ad-ditional information in this chapter includes server-side JavaScript integration and an excursion into the vast supply of ready-made jQuery plugins.

Appendices

Information on how to install Drupal and contributed modules is included in Ap-pendix A. Appendix B contains the code samples that are referenced in the JavaScript chapters. These code samples can also be downloaded from the book’s Web site.

00_9780132979245_FM_A.indd viii 1/6/12 9:47 AM

Acknowledgments

Emma wishes to thank her mum, Maryann Thomas, for making sure Emma didn’t die of scurvy while writing the book. Thanks also to Kim Werker, for trusting me with CrochetMe; Steven Champeon, for his endless patience and insistence that Web sites be built properly; and Bernie Monette, for introducing me to fountain pens and teach-ing me how to spell “awkward.” Thanks to all my reviewers and my production team at Pearson, and especially to Lynda Chiotti, who also provided an ear as I worked through my fi rst Real Book with a Big-Time Publisher. The Drupal Documentation Team pro-vided the empathy and the encouragement I needed to get things done—thanks! And fi nally thanks to LugRadio Live, for inviting me to speak at their conference and in-advertently introducing me to Debra Williams Cauley, the best acquisitions editor an author could hope for!

Konstantin fi rst and foremost wants to thank his parents, Gertrud and Friedrich, for enabling him to dive into computer technology at a time when home computers weren’t as common as they are today and for their tremendous support at all times. Thanks to NowPublic Technologies, which helped and supported me while writing this book. Thanks also to Károly Négyesi, also known as “chx,” for the unbelievable work he has done and is still doing for the Drupal community; to Steven Wittens, for his inspira-tion and creativity; and to Susanne Weigel, for teaching me how to create mind maps. Finally, thanks to Debra Williams Cauley for bearing with missed deadlines and for poking me when I was procrastinating too much.

Thanks also to the following businesses who graciously allowed us to capture images from their Web sites: Trillium Healing Arts Centre, Toilet Birthdays, The Ginger Press, CrochetMe (Interweave), CSS Zen Garden, Ubuntu Screencasts, Memory Garden Re-treats, and Hear the North.

00_9780132979245_FM_A.indd ix 1/6/12 9:47 AM

x

Emma Jane Hogbin has been working as a Web developer since 1996, helping indi-viduals and organizations to realize both their own potential and the potential of their online presence. She creates systems that enable her clients to succeed—by using her infectious enthusiasm and ability to explain concepts without using technical jargon that puts even the greatest technophobes at ease. Passionate about helping people to acquire knowledge, Emma volunteers with the Drupal and Ubuntu documentation teams. She is well known in the Drupal community not only for her technical knowl-edge, but also for her engaging and humorous means of bringing Drupal to a wider audience—such as the Drupal socks and their GPLed pattern. Through her consult-ing company HICK Tech, and at conferences around the world, Emma has inspired people to overcome fear, uncertainty, and doubt and to tackle problems head-on. She is known as “emmajane” on drupal.org and chronicles her adventures at http://www.emmajane.net.

Konstantin Käfer started his adventures into Web development in 1999. In high school, he led the Web development and school Web site class for several years. While still in high school, he also participated in Google’s Summer of Code 2006, doing us-ability enhancements for the Drupal project. In the Drupal community, he is widely known for his JavaScript skills. Konstantin has been a speaker at several DrupalCons and other Open Source conferences. He is currently studying IT Systems at the Hasso Plattner Institute Engineering in Potsdam, Germany. He also works as a consultant for NowPublic, a large citizen journalism Web site based on Drupal. He can be found blogging on http://kkaefer.com about design, Web development, and Drupal.

About the Authors

00_9780132979245_FM_A.indd x 1/6/12 9:47 AM

73A

The actual creation of a Drupal theme is very simple. In this chapter you will learn the fundamentals. Following instructions blindly may end up feeling a

bit like working through a “learn to draw” book you may have had as a child. Step 1: Draw a circle. Step 2: Add eyes, nose, mouth, and ears. Step 3: Add hair. Step 4: Apply your sketching skills to render the stick figure into a masterpiece that pos-sesses depth and beauty and makes old men weep at a mere glance. Sound a bit like theming Drupal? Hang in there! This chapter will fill in many of the blanks between steps 3 and 4 from your old drawing book!

This chapter outlines the basics of finding, installing, and configuring a Drupal theme. You will learn how to create a lean Drupal theme from scratch to see the component parts—and also how to create a feature-rich subtheme from one of the many theme starter kits that are available for Drupal. The chapter wraps up with a brief look at how to convert older themes to Drupal 6, and how to convert themes from other content management systems to Drupal.

3

Working with Drupal Themes

03_9780132979245_ch03_A.indd 73 1/3/12 12:51 PM

74A Chapter 3 Working with Drupal Themes

Finding Themes

The easiest way to theme your Drupal Web site is to start with a prebuilt theme that appeals to you. By swapping the banner image and changing the background color, you can transform a template with very little additional work.

In addition to the themes that ship with Drupal, premade Drupal themes can be found in many other places. A quick Web search for “Drupal themes” will turn up at least a few hundred thousand Web sites. The search results will range from free themes that may have been downloaded and implemented by lots of other Web sites to completely unique designs created by specialist-design companies. Depending on your time and budget, you may fi nd any of these themes useful for your Web site.

CopyrightThe designs listed in this section are not necessarily free to modify and use. Many of the templates are licensed under the Creative Commons and can be used if

credit is given to the original designer. Please respect the terms of the individually licensed designs.

Generally the templates available from the Drupal Web site (http://drupal.org/project/Themes) and the Theme Garden (http://www.themegarden.org) are ready to be installed and used on your Web site. When you are selecting a theme, make sure you choose one that matches the version of Drupal you have installed. Themes that were created for Drupal 5 will not work with Drupal 6, for example. The list of themes on Drupal.org can be fi ltered based on the version of Drupal you are running. You must be logged into your Drupal.org account to use this fi lter.

Create a Drupal.org accountMany packages are available from Drupal.org. By creating an account, you can easily fi lter these packages for the version of Drupal you are using. Registration is

free. To create a new account, go to http://drupal.org/user/register.

Figure 3.1 shows the Theme Garden—a preview site for the themes that can be downloaded from Drupal.org. There is not always a perfect match between the two lists, however, so be sure to check both sites for appealing designs.

03_9780132979245_ch03_A.indd 74 1/3/12 12:51 PM

FIGURE 3.1 The Drupal Theme Garden allows you to see how themes look on a real site with actual con-tent. This is the Theme Garden styled using the Amadou theme.

The Drupal.org theme directory is set up a little differently (Figure 3.2). Each theme listed gives a summary of the theme, but not a full implementation of it. Details on the summary page for each theme include these items:

• A text description of the theme, including its features

• The version of the theme as well as its release date

• A screenshot giving a view of the “above the fold” view of the theme

• A link back to the project Web page for the theme (if one exists)

If you need new themes on a regular basis, take the time to fi nd a theme directory that you like using. Each directory will have slightly different features. Themebot (http://www.themebot.com/website-templates/drupal-themes), for exam-ple, lists W3C compliance, indicates whether a design has a fi xed or fl uid width, and gives a full demo showing how content will be styled in blocks, sidebars, and the content area.

Finding Themes 75A

03_9780132979245_ch03_A.indd 75 1/3/12 12:51 PM

76A Chapter 3 Working with Drupal Themes

FIGURE 3.2 Drupal.org provides the same information for modules and themes as the Drupal Theme Garden. This is the project page for the Amadou theme.

Interface Components

When selecting a theme, it is important to consider the various page elements that you identifi ed while working through the “Interface Components” section in Chapter 1. These features include how many columns the page contains, how the page expands into the available space (and how it contracts for narrower browser windows), which font sizes are used, and whether a search box has been integrated into the design. If you are trying to emulate an existing Web site design, you may want to skip ahead in this chapter and read the sections on how to convert a template into a Drupal theme.

Nearly everyone is drawn to color fi rst and structure second. In some cases a design may be available in several different colors. The color may be controlled from within Drupal, or you may need to choose which colors you want to download the right theme. Designs can also be easily modifi ed by altering the CSS style sheet and using the “Colorize” function within a graphics program such as GIMP or Photoshop. By altering the lightness and the hue of a color, you can convert a gray-scale design into

03_9780132979245_ch03_A.indd 76 1/3/12 12:51 PM

a colored one. Conversely, you can switch a colored design to black and white by converting your graphics from RGB to gray-scale. You may fi nd this ability especially useful if you are showcasing or selling products—a neutral interface will compete less with your content. A full tutorial on how to colorize a theme using the Color module is available at http://drupal.org/node/220789.

Refer back to the design decisions you made in Chapter 1 to help you choose a template with the appropriate number of regions for your content. If your design needs many small regions, take a moment to think about the content area: Should it be fl uid and expand in wider display screens to give more visual importance to the content, or should it be fi xed in size? In the Drupal Theme Garden you can resize your browser to see how the theme adjusts to different browser conditions.

If your site is a blog, and will only ever be a blog, chances are good you will be completely satisfi ed with a simple two-column design. By contrast, if you know your site will grow beyond its current wireframe within a short amount of time, you should consider using a template that can easily accommodate additional regions. Although many themes are limited to 4 or 5 regions, others have defi ned more than a dozen separate regions. If you do not need all the regions initially, be sure to check that the design collapses gracefully to suit your needs.

Develop a Library of Themes

It is very easy to apply a Drupal theme. If you see a number of themes you like, down-load them all! You can install each of the themes and test it with your own content before making a fi nal decision on which theme to use. You may also want to keep a library of themes that you like, but aren’t a perfect match for your current project. Be sure to store the themes in a way that makes it easy to retrieve exactly the right theme later on. Create a summary of the themes as well as a description of what you liked about the theme.

Zotero is an excellent design archiving tool. This Firefox extension allows you to take a snapshot of a Web page along with your notes (see Figure 3.3). Originally developed to help researchers collect, manage, and cite research sources, Zotero cre-ates a library of Web pages on your computer for offl ine browsing. Additional features include the ability to take notes on a per-page basis, add tags to the page, and rename the page title. The ability to access and maintain the pages locally can prove very useful if you are in a meeting in a location that does not have an Internet connection. Zotero can be downloaded from http://www.zotero.org.

Finding Themes 77A

03_9780132979245_ch03_A.indd 77 1/3/12 12:51 PM

78A Chapter 3 Working with Drupal Themes

FIGURE 3.3 Zotero, a Firefox extension shown in the bottom of this screenshot, makes it easier to man-age an offl ine gallery of themes. The tool integrates itself into Firefox and can be hidden or displayed using the “Zotero” icon in the lower-right corner of the browser.

Installing Drupal Themes

Once you’ve selected your theme, your next task is to install it.

Download and Unpack

Several fi les are included in a theme. These fi les will be packaged up and compressed to make it faster for you to download them. To prepare a new Drupal theme for use on your site, follow these steps:

1. Choose the right package for your Drupal installation. Themes that were de-signed for Drupal 5 cannot be used on a Drupal 6 Web site, for example.

2. Click the “download” button or link.

3. You will be prompted by your Web browser to save the file. Choose a location on your computer that you will remember—perhaps in your project folder for a specific Web site or on your desktop.

4. The browser may also ask you if you want to unpack the files. Go ahead and unpack the files if you are given the option to do so.

03_9780132979245_ch03_A.indd 78 1/3/12 12:51 PM

Look at the fi les inside the theme package. If a fi le named README or INSTALL is present, be sure to read it. This kind of plain text fi le can be opened in any simple text editor.

Within the theme, there are several components, each of which must be placed into an appropriate home. The design elements are handled by style sheets; the graphics and the interactive behaviors are handled by JavaScript. The markup is handled by tem-plate fi les with the extension tpl.php . Logic, function calls, and variable assignments are handled exclusively by the fi le template.php. As a consequence, there should not be any markup in the template.php or any function calls in the individual tpl.php fi les. In your theme’s folder, you will likely fi nd the following fi les:

• An info file (themename.info)

• A page template (page.tpl.php)

• PHP functions that create new variables and alter the default variables pro-vided by Drupal (template.php)

• A style sheet (themename.css or style.css)

• A screenshot (screenshot.png)

Although the only required fi le is the .info fi le, a theme won’t be much of a design without at least one template fi le and a style sheet. The screenshot is provided to help you choose the right theme from the list of themes in the Drupal administration area; it is not used in the actual theme design.

Drupal ships with several default themes, which are stored in the themes directory. To distinguish your uploaded themes from the default ones, store your new themes in the sites folder. If you would like to make your theme available to all Web sites, upload the fi les to sites/all/themes/themename. If you would like your theme to be available to only one of your Web sites, upload it to sites/websiteurl.com/themes/themename. In both of these examples, “themename” will be the name of the folder on your computer that contains the theme. You may need to create a subdirec-tory named “themes” in the relevant “sites” folder.

Enable the New Theme

Once your theme is uploaded to your Web server, you will need to enable it in the Drupal administration area. Drupal provides an easy-to-use theme selection screen, as shown in Figure 3.4. This screen allows you to preview each of the themes (using a

Installing Drupal Themes 79A

03_9780132979245_ch03_A.indd 79 1/3/12 12:51 PM

80A Chapter 3 Working with Drupal Themes

static screenshot created by the theme designer) and offers a link to additional confi gu-ration options that are available for the theme.

To enable the new theme, follow these steps:

1. Log into the Web site as the administrator.

2. Choose the “Administer” link from the navigation on the left (or “administra-tion section” from the front page).

3. Choose “Themes” from the list of options on the main administration screen.

4. Scroll down to your new theme, select the check box to “Enable” the theme, and select the “Default” radio button to activate the theme.

5. Scroll to the bottom of the Web page and click “Save configuration.”

Your new theme should now be applied sitewide!

FIGURE 3.4 Use the Theme settings administration area to select the theme you want applied to your Web site. Multiple columns of information help you to enable the right theme for your Web site.

03_9780132979245_ch03_A.indd 80 1/3/12 12:51 PM

Personal Themes

If your Web site is already live, you may want to enable your new theme privately to test its implementation before showing it to the rest of the world. To do so, you can use the “Personal Themes” feature of Drupal. It allows you to enable a theme that only you can view. Once the theme is working correctly as a personal theme, you can apply the theme to the entire Web site for everyone to use by following the instructions in the previous section.

If you are not the main administrator for the site (user/1), you will need to adjust the permissions so that you can use the Personal Theme feature.

1. From the Administration main page, navigate to the “Permissions” screen.

2. Scroll down to the “System” options and check the box for the appropriate role to “select different theme” as shown in Figure 3.5.

3. Scroll to the bottom of the Web page and click “Save permissions.”

FIGURE 3.5 Under the system module section, set the permissions for personal themes to test your theme before publishing it on your live Web site.

Installing Drupal Themes 81A

03_9780132979245_ch03_A.indd 81 1/3/12 12:51 PM

82A Chapter 3 Working with Drupal Themes

Once you have enabled your personal themes, you must confi gure the theme you would like to use for your account. To enable your personal theme:

1. In the Drupal navigation menu, navigate to “My account.”

2. Click the “Edit” tab on your personal account.

3. Scroll down to the “Theme configuration” section as shown in Figure 3.6 and select the radio button next to your new theme.

4. Scroll to the bottom of the screen and click “Save.”

Your new theme will now be enabled for only your account. When your theme has been completely customized and you know it is bug free, you may apply it to the entire site using the steps given in the previous section. If you have altered settings within the Drupal administrative section for your theme, you will need to reapply these changes when your theme is made public.

Administering Themes

Once your theme is installed, you will need to adjust several settings to customize the theme for your Web site. Although some of these settings were confi gured as part of the

FIGURE 3.6 In the “Theme confi guration” section of your account page, you can select a “personal theme” if you are a member of a role that has the correct permissions.

03_9780132979245_ch03_A.indd 82 1/3/12 12:51 PM

global theme when you fi rst installed Drupal, there may be additional aspects of your theme that you need to customize. Theme-specifi c settings rely on variables within the theme’s template fi les. If your theme does not use these variables, changes you make in the administration area will have no effect.

Global Settings

A single administration screen allows you to control the default display settings for your entire site, across all themes. The same screen is also provided on a per-theme basis and allows you to override any of the global settings. To access this confi guration screen, click the “confi gure” link next to the theme name on the list of themes outlined in the previous section. To have these changes apply across all themes click the “Global settings” link near the top of the page as shown in Figure 3.7 before continuing.

FIGURE 3.7 Some theme settings can be applied across all current and future themes by using the Global settings screen.

Administering Themes 83A

03_9780132979245_ch03_A.indd 83 1/3/12 12:51 PM

84A Chapter 3 Working with Drupal Themes

Take a moment to scan through all of the confi guration options to you. Toggle display allows you to turn off or on some of the sitewide variables:

• Logo

• Site name

• Site slogan

• Mission statement

• User pictures in posts

• User pictures in comments

• Search box

• Shortcut icon

• Primary links

• Secondary links

The site name, site slogan, and mission statement are text snippets that you wrote when you fi rst installed Drupal. If you want to edit this text, you must navigate to Administer, Settings, Site Information.

In addition to changing the options listed previously, you can specify whether the ownership and time stamp information will be viewable on each of your pages. Each time a new content type is added to (or enabled on) your Drupal installation, you will need to return to this page to adjust its settings.

From the Global settings screen, you can change the sitewide logo. You may either choose a logo that has already been uploaded or upload a different logo through the Web-based interface. The shortcut icon (the favicon.ico fi le) can also be adminis-tered in the same way.

Theme-Specific Settings

Your theme can override the global settings defi ned in the previous section. You should also defi ne the settings for your individual theme if your site is using different themes for the Administration pages and for the public Web site. In addition to the global set-tings, your theme may have additional settings to confi gure. Navigate to Administra-tion, Site Building, Themes and click on the link “confi gure” next to your theme.

In the Zen theme, the following additional settings are available:

03_9780132979245_ch03_A.indd 84 1/3/12 12:51 PM

• Show block editing on hover

• Customizable breadcrumb separators

• Theme development settings

Different options may be available for your specifi c theme.

The Front Page

There are several ways to customize the front page of your Drupal Web site. Each technique must be themed in a different way. This section outlines the steps needed to implement each solution from the Web site administration area. Each section also includes the reference to a later chapter where the theming of this type of front page content is described in full.

Single “Welcome” Node

Some Web sites are very simple. They have a few pages of content, a contact page, perhaps a summary of upcoming workshops, and not much else. For this type of Web site, you should create a “home” or “welcome” page and assign it to the front page of the Web site using the following steps:

1. Click the "Create content" link from the Drupal-provided Navigation menu.

2. Choose the content type “Page.”

3. Add a title and body for the page.

4. Scroll down to the “Publishing options.” These options are hidden by default. You will need to click on the link to open the menu options.

5. Add a check mark beside “Promoted to front page.”

6. Scroll to the bottom of the Web page and click “Save” to save your page.

This page should now appear as the front page of your Drupal Web site.Another way to set the front page is to give Drupal a specifi c page to load within

the Site information administration area. If you are working with an existing Drupal site and cannot fi gure out what is being displayed on the front page, check this option. Using only the core modules within Drupal, you can also confi gure this setting to have only one category of content be displayed on your front page. For example, you might want to highlight only those nodes that belong to the category “Front Page News.”

Administering Themes 85A

03_9780132979245_ch03_A.indd 85 1/3/12 12:51 PM

86A Chapter 3 Working with Drupal Themes

To set the front page to a specifi c category, you will need to know the URL for the category you want to highlight.

1. Navigate to the category page which lists all nodes for that category.

2. Copy the query string for this page from your browser’s address bar. It will be something like taxonomy/term/113.

3. Navigate to Administer, Site Configuration, Site information.

4. Scroll to the bottom of the page and copy your query string into the “Default front page” form field. Ensure you have only the query string and not the domain name of the Web site, as well.

5. Click “Save configuration.”

6. Navigate to the front page of your Web site to confirm the changes have been applied correctly.

Content Teasers

At this point you may notice that only a partial summary of your content appears on the front page along with a “Read more” link, instead of the entire page. If you are happy with this format, excellent! What you are viewing is a list of “teasers” instead of the full node. The length of this text can be adjusted in the “Post settings” section of the administration area. To display the full node on the front page instead of a teaser, use the following steps:

1. Navigate to Administer, Content management, Post settings.

2. Change the “Number of posts on main page” to a number that is appropriate for your site (the default is 10).

3. Change the “Length of trimmed posts” to “Unlimited.”

4. Scroll to the bottom of the screen and click “Save configuration.”

To make your Web site load more quickly, Drupal stores the “teaser” as a separate fi eld in the database. To make changes to your content retroactively, you will need to go back and re-save the items currently appearing on the front page. Navigate to the page you want to change, click the “Edit” tab, and re-save the page.

You can also force the teaser to split in a certain way by clicking the “Split summary at cursor” button; Figure 3.8 shows the results. Click the “Join summary” button to return to the default content editing confi guration.

Chapter 5 provides more information on ways to style content teasers.

03_9780132979245_ch03_A.indd 86 1/3/12 12:51 PM

FIGURE 3.8 Use the “Split summary at cursor” button to create a visual break between the teaser of your story and the rest of the content. The resulting screen shows the teaser and remainder of the full content mode.

Several Nodes “Promoted to Front Page”

The default option for “Promoted to front page” can be set per content type. This option allows you to create a news-style front page that lists all new items of that con-tent type by default. To set the default options for a specifi c type of content, you will need to set your preferences in the administration area for that content type.

1. Navigate to the administration page for a specific content type by following the path Administer, Content management, Content Types.

2. Click the “edit” link for the type of content you would like to modify. Drupal provides you with two content types: Page and Story. In Chapter 2, you also learned how to create your own content types. Choose the content type you wish to alter.

Administering Themes 87A

03_9780132979245_ch03_A.indd 87 1/3/12 12:51 PM

88A Chapter 3 Working with Drupal Themes

3. Scroll to “Workflow settings” and click the link to open the configuration menu.

4. Add a check mark beside “Promoted to front page.”

5. Scroll to the bottom of the Web page and click “Save content type.”

Any new items that are added from that content type will now be published to the front page by default. You may disable this option when you are creating or editing the page if you do not want those items to appear on the front page.

Anatomy of a Theme

Whether you are creating a theme from a basic HTML template or converting a theme from another Web-based content management system, the fi rst step is always to con-vert your fi les to a simple Drupal theme. You can then add as much complexity as you like. In this section we examine the steps required to create a page template for a basic theme.

Naming and Initializing the Theme

Coming up with a name for your theme is perhaps the most diffi cult part of this set of instructions. The fi rst Drupal theme you create can be created before fi nishing your morning’s coffee and certainly will not require any kind of fancy skills that you will need to be wide awake to create and replicate. This new Drupal theme is affectionately named Bolg. (Yes, Bolg—the goblin chieftain and the son of Azog.) Adjust this theme name to suit your needs.

Use unique namesYour theme must have a name that is unique to Drupal. This restriction applies to the directory that holds your theme, not the human-readable theme name.

It means you cannot use the same directory name as a module that is installed, or the name of a PHP function. If your theme name is already in use, your site may not function correctly, if at all.

The fi rst thing Bolg needs is a home on your computer. Create a new folder for your theme fi les. Use the name of your theme—for example, “bolg.” In the bolg directory, add a new text fi le that has the same name as your new theme directory and the suffi x .info. For example, create a text fi le called bolg.info that resides in the directory named “bolg.” This info fi le will contain information about your theme.

03_9780132979245_ch03_A.indd 88 1/3/12 12:51 PM

You will start with only the most basic information:

name = Theme Bolg

description = The theme of the goblin chieftain.

core = 6.x

engine = phptemplate

You should customize your .info fi le to give the name of your theme as well as a description of it. The core variable should match the DRUPAL_CORE_COMPATIBILITY defi ned in modules/system/system.module. This may be version 6.x or higher. Prior to this version, Drupal handled themes differently. The engine variable refers to the template engine that will be used to compile your theme. Use phptemplate for the engine variable. Although Drupal does support several template engines, by far the most common is phptemplate. If you have inherited a theme that is not using phptemplate, refer to the online documentation at http://drupal.org/node/176129 for more information.

Page Template

The next thing to do is create a simple page template for your Drupal theme. You will start with a very simple static XHTML fi le to learn the basics of theme building. More complicated XHTML templates can be used at this time if you already have an XHTML template created. The Bolg template is based on the XHTML 1.0 Strict template from the Web Standards Project. It can be downloaded from http://www.webstandards.org/learn/reference/templates/xhtml10t/. It contains the following XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN”

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Conforming XHTML 1.0 Strict Template</title>

</head>

<body>

</body>

</html>

Anatomy of a Theme 89A

03_9780132979245_ch03_A.indd 89 1/3/12 12:51 PM

90A Chapter 3 Working with Drupal Themes

Paste this template into a new fi le named page.tpl.php. This fi le will serve as the basic framework for everything else; that is, you will drop variables into it.

If you are working from a rendered HTML page, you will need to remove the content from the page, leaving only the markup that surrounds your page template regions. You will also need to copy the associated images, CSS, and JavaScript into your theme’s directory (and rename your index.html fi le to page.tpl.php).

Work with an HTML pageIf you are converting your site from a Web-based content management system to Drupal, you may fi nd it easier to work from a Web page that has been processed

for display in a Web browser instead of the template source fi les. This processed page is also referred to as a “rendered” page. By using the output instead of the source fi les, you will be able to see exactly how the page ought to fi t together by the time it reaches the Web browser.

In the fi le page.tpl.php, you will need to replace the text with the variables Drupal needs to deposit content into the right places. Here is a quick summary of the changes made to the Bolg template page:

• Replaced the contents of the <title> tag with Drupal’s PHP variable $head_title

• Placed the variables $head, $styles, and $scripts into the <head> tag of the template

• Placed the page content, and its associated variables, into the <body> tag of the page

• Added the variable $closure to the bottom (this variable is used by modules such as Google Analytics)

The template now looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title><?php print $head_title; ?></title>

<?php print $head; ?>

03_9780132979245_ch03_A.indd 90 1/3/12 12:51 PM

<?php print $styles; ?>

<?php print $scripts; ?>

</head>

<body>

<?php print $title; ?>

<?php print $tabs; ?>

<?php print $help; ?>

<?php print $messages; ?>

<?php print $content; ?>

<?php print $feed_icons; ?>

<?php print $closure; ?>

</body>

</html>

In Chapter 4, you will learn how to expand this code into a complete template, including additional page variables and navigation. For now, it is useful to see the vari-ables without having to wade through additional markup.

Including External CSS and JavaScript Files

If you are using external CSS and JavaScript fi les, you will need to update the fi le bolg.info. To identify your style sheet, use the stylesheets array in your .info fi le. It may contain values like these:

; Add style sheets for all media

stylesheets[all][] = bolg.css

stylesheets[all][] = navigation.css

; Add a style sheet for screen and projector media

stylesheets[screen, projector][] = projector.css

; Add a style sheet for print

stylesheets[print][] = print.css

Anatomy of a Theme 91A

03_9780132979245_ch03_A.indd 91 1/3/12 12:51 PM

92A Chapter 3 Working with Drupal Themes

If you have the fi le style.css, it will be automatically included in your page tem-plate only if no other style sheets are defi ned in your .info fi le. Additional informa-tion about including style sheets in a Drupal 6 theme is available at http://drupal.org/node/171209.

If you would like your JavaScript fi le to be automatically included, use the fi le name script.js. If you would like to include additional JavaScript fi les, you will need to update your .info fi le. Your theme’s JavaScript fi les must reside in your theme’s home directory. Off-site JavaScript fi les will not be included, as they represent a potential security threat to your site. In your theme’s .info fi le, add the following line for each JavaScript fi le:

scripts[] = myscript.js

Regions

Regions can be placed throughout your template. First, however, they must be defi ned in the .info fi le for your theme; only then can the corresponding variable names be placed into your page template. You may have as many regions as you would like for each theme. Regions are defi ned by setting both the PHP variable name and a human-readable text name as follows:

regions[left] = Left sidebar

regions[right] = Right sidebar

regions[above_text] = Above content

regions[below_text] = Below content

Although three regions ($left, $right, and $footer) are available by default, they will appear only if you do not have any of your own regions defi ned. If you would like to use these defaults as well as your own regions, you must explicitly set the default regions in the same way as your new, custom regions.

Not all feet are the same$footer_message is the snippet of text defi ned on the site information page; $footer is a region on the page where you can place blocks.

03_9780132979245_ch03_A.indd 92 1/3/12 12:51 PM

To place these region variables in the template, you may wish to add a conditional statement around the outside of each variable so that the container elements are printed only if the region is being used. This approach will allow you to collapse and expand your page as appropriate. The following snippet shows how the HTML markup that contains the variable $header is printed only if the variable is actually set.

<?php if ($header) { ?>

<div id="header">

<?php print $header; ?>

</div>

<?php } ?>

The Drupal convention is to print PHP inside HTML rather than to print HTML markup from PHP. In other words, you would use the sample markup above and avoid using the following format in your templates:

print "<h2><a href=\"$node_url\" >$title</a></h2>";

Screenshot

If your theme has some basic colors, you may also want to include a screenshot at this point to give a visual cue as to its nature on the theme selection page. This “thumbnail” typically consists of a screenshot of the theme, although it could be any image that distinguishes your theme from the others installed on the Web site. The image should be approximately 150 pixels wide and included in the home directory for your theme. Update the .info fi le to include a reference to your thumbnail. This information should be included near the top of the fi le along with the theme name:

screen shot = screenshot.png

If you plan to distribute your theme to the wider Drupal community, you should fol-low the screenshot guidelines that are included in the Theming Handbook at http://drupal.org/node/11637. Broader guidelines for publicly distributed themes on Drupal.org are available at http://drupal.org/node/14208.

Anatomy of a Theme 93A

03_9780132979245_ch03_A.indd 93 1/3/12 12:51 PM

94A Chapter 3 Working with Drupal Themes

Starter Themes

It is a quick process to download a theme that matches your design and to customize it to meet your needs. Literally hundreds (if not thousands) of Drupal themes can be downloaded and used immediately; not surprisingly, the quality of these themes varies greatly. It is a distinct possibility that you will spend as much time adapting a down-loaded theme to use each of Drupal’s page variables as if you had created your own theme from scratch.

The alternative to working with mediocre themes is to begin with a Drupal starter theme that has an entire toolkit of Drupal-specifi c functions and customizations. Of course, if you need a little bit of design inspiration, there are certainly advantages in downloading a theme that is visually similar to your wireframes, and then rebuilding it using a starter kit. By taking this route, you get the advantage of working with a complete visual design (including banner images and icons) and a full suite of Drupal functions (including customized administrative links like those available in the Zen starter kit).

You do not need to rely exclusively on your imagination to create both the visual design and the code for a truly excellent theme. The default theme, Garland, has received a good scrub and can now be used as inspiration for your new theme. Several other starter kits are available as well. These kits, which typically have very little style, are intended to serve as a launching point for building your own unique Drupal theme. Each kit uses a CSS, table-free layout and has been tested in a variety of browsers. The documentation explaining how to implement each starter kit varies. Following are the sources for some popular starter kits:

• Zen: http://drupal.org/project/zen

• Genesis: http://drupal.org/project/genesis

• ATCK: http://drupal.org/project/atck

• Basic: http://drupal.org/project/basic

• Beginning: http://drupal.org/project/beginning

• Blueprint: http://drupal.org/project/Blueprint

• Clean: http://drupal.org/project/clean

• Flexible 2: http://drupal.org/project/flexible

• Foundation: http://drupal.org/project/foundation

• Framework: http://drupal.org/project/framework

• Hunchbaque: http://drupal.org/project/hunchbaque

• Tendu: http://drupal.org/project/tendu

03_9780132979245_ch03_A.indd 94 1/3/12 12:51 PM

An in-depth comparison of these starter kits is available at http://drupalstaging.com/starter-themes/starter-theme-comparison.html.

Zen

Touted as being “the ultimate starting theme for Drupal,” the Zen starter kit provides an example of how to implement all of the basics. Its markup is clean and extensively documented. Whether you use it as a reference guide, pulling out the elements you need, or use the actual fi les as a base for your own theme, Zen will help you to produce cleaner themes, faster. Even a simple design is worthy of beginning with a starter kit like Zen. Although it is a simple template, the Web site shown in Figure 3.9 was built using the Zen starter kit. Going from a graphic fi le in GIMP to a deployed theme took less than a day—all because of Zen. The headaches of fi guring out cross-browser, CSS-based design were completely eliminated.

FIGURE 3.9 The Memory Garden Retreats theme was built using the Zen starter kit in less than a day. Although this theme uses a simple Web template, its creation was virtually effortless thanks to the use of the easy-to-use starter kit.

Starter Themes 95A

03_9780132979245_ch03_A.indd 95 1/3/12 12:51 PM

96A Chapter 3 Working with Drupal Themes

You can download the Zen theme from http://drupal.org/project/zen. Unpackage the fi les and place the entire directory (and subdirectories) into the sites/all/themes folder. The Zen package contains several themes, including a starter kit and Zen Classic. You can enable these themes by navigating to Administer, Site build-ing, Themes. The Zen theme will help you to identify each area of a Drupal installa-tion that can be customized and themed. Working with the Zen theme is much like working with the core of Drupal—you do not need to alter the main fi les. Instead, you create a subtheme that customizes every single element available in the main Zen theme (or perhaps retains some of the Zen’s features).

Use the following steps to create a new subtheme named “Frodo:”

1. Create your own Zen subtheme by making a copy of the STARTERKIT folder within the zen folder.

2. Rename the folder to your new theme name; rename the .info file contained in the copied STARTERKIT folder to the same name as the folder it is contained in. For example, if you named your directory frodo, the corresponding .info file would be named frodo.info.

3. Rename the zen master CSS file to match your theme name. For example, zen.css should be renamed to frodo.css.

4. Copy the liquid, or fixed-width, CSS file from the main zen folder into the frodo folder.

5. Copy the print CSS file from the main zen folder into the frodo folder.

6. Edit the frodo.info file by changing the settings for the theme’s name, description, and new CSS file names.

7. Edit the template.php and theme-settings.php files by changing all instances of STARTERKIT to your theme’s name (“frodo,” in this example).

8. Enable your new theme in Drupal’s administrative Web interface by navigating to Administer, Site building, Themes.

9. Continue to adjust each of your new theme’s settings and styles to suit your needs.

In addition to the Zen project, a series of default templates are available for many differ-ent core Drupal components. Most of these fi les correspond to specifi c modules and can be copied directly from your Drupal installation’s core fi les. For example, three template

03_9780132979245_ch03_A.indd 96 1/3/12 12:51 PM

fi les are available within the folder modules/comment: comment-folder.tpl.php, comment-wrapper.tpl.php, and comment.tpl.php. Throughout this book you will learn about these default templates and discover how to customize them to suit your needs.

Custom Theme Settings

The Zen theme takes advantage of the custom theme settings that are available in Drupal 6. When you use the Zen starter kit, you have at your fi ngertips a sample template that explains how to add even more custom settings to your theme. The Zen starter kit includes the following custom settings by default:

• Show block editing on hover

• Breadcrumb settings (including separators and pages on which to show/hide breadcrumb settings)

• Theme development settings (liquid versus fixed layout), and show borders around main layout elements to emulate wireframes

To view or alter these settings, navigate to Administer, Site building, Themes. Enable the relevant theme (for example, Zen or Zen Classic). Select the relevant “confi gure” link now displayed next to the Zen theme(s) you have enabled. Figure 3.10 shows the settings page—it has a form with the global settings at the top as well as any theme-specifi c settings toward the bottom of the page. To add new set-tings to this page, you must alter the fi le named theme-settings.php in the rel-evant Zen theme directory. If you are using the starter kit, you already have a copy of this fi le in your theme’s directory. Within this fi le you may add new items to your theme’s setting by using the Form API.

If the sample settings in the Zen theme are not suffi cient for you to create your own settings, read the Advanced Theme Settings tutorial at http://drupal.org/node/177868.

Customizing Banner Images

When working with starter kits, you may still want to download a theme, if only to use it for visual inspiration. Look for themes that inspire you not just through their pho-tographs and icons, but also in terms of their color scheme, use of fonts, and layout.

Starter Themes 97A

03_9780132979245_ch03_A.indd 97 1/3/12 12:51 PM

98A Chapter 3 Working with Drupal Themes

Figure 3.11 shows that changing only the banner can make a great difference in the tone of the design.

To customize the banner for any theme requires only a few steps and rudimentary skills with a graphics editing program.

FIGURE 3.10 By altering the fi le theme-settings.php, you can add new theme-specifi c settings to the theme’s confi guration screen. Shown here are the Global settings (top) and theme-specifi c settings (bot-tom) for the Zen theme.

03_9780132979245_ch03_A.indd 98 1/3/12 12:51 PM

1. Create a backup of the current banner by copying the file to a new name (you will now have two identical banner images with different names).

2. Using a graphics program (such as GIMP or Photoshop), open the banner image provided by the theme (the one with the original file name).

3. Open the image you would like to use in your new banner. Copy and paste the image into the existing banner. You may need to enlarge or reduce the size of the new banner image so that it fits within the size constraints of the theme’s original banner image.

4. Using the theme’s original file name for the banner, save the new file. Your new banner image will now appear in the theme.

Migrating to Drupal 6

Many different content management systems (CMS) are available. Whether your expe-rience is with another Web-based CMS or even an earlier version of Drupal, change in the systems you use—whether to a different system or to a different version of the same system—is inevitable. This section focuses on the process of evaluating a template with

Migrating to Drupal 6 99A

FIGURE 3.11 The same theme with two different banner images.

03_9780132979245_ch03_A.indd 99 1/3/12 12:51 PM

100A Chapter 3 Working with Drupal Themes

the goal of converting it to Drupal 6. The fi rst step to migrating from one system to another is to carefully analyze both the current system and the new system, looking for similarities and differences between the two. If you are a visual thinker, you may even want to sketch a simple Web page and mark (in two different colors) the naming conventions employed by your current system and those used by Drupal.

Regardless of which system you are migrating from, a basic Drupal theme can be built from any template. If you are not a code monkey at heart, you may fi nd it easier to work from a HTML page that is built by the CMS and its template, instead of using the content management system’s template fi les. Review the fi rst section of this chapter for more information on converting a fl at HTML fi le to a Drupal theme.

Converting a Drupal 5.x Theme to a Drupal 6.x Theme

Drupal themes have changed radically from version 5 to version 6; however, there is no reason to change the design of a page that is displayed to Web site visitors when you upgrade the theme from one version of Drupal to another. Keeping this point in mind, you should fi nd it a relatively quick task to upgrade a theme with only a few minor changes to your current theme fi les. Work through the following checklist to create a Drupal 6 theme:

1. Create an information file for your theme. This file must have the same name as the directory that holds the theme’s files and have the extension .info. It must contain the basic information about your theme, including its name, its description, the core version of Drupal the theme can be applied to, and the template engine.

2. Remove “region” definitions from your template.php file. List them in the themeName.info file, instead.

3. Confirm that the variables you have set in your template files match the cur-rent default variable names.

4. The phptemplate_callback() function has been replaced by individual tpl.php files. Remove relevant functions from the template.php file and place the themed markup into its corresponding tpl.php file. For example, the contents of phptemplate_breadcrumb() should be placed into the file breadcrumb.tpl.php.

03_9780132979245_ch03_A.indd 100 1/3/12 12:51 PM

5. Substitute the $layout variable in your template files for $body_classes. Update your CSS files according to the new classes defined. Classes can be used to identify front and internal pages, logged-in users and visitors, node ID and node type, and visible sidebars.

6. The $language variable is now an object. To update your theme, change this variable to $language->language.

7. jQuery version 1.2.3 is now included by default. Scripts can also be placed into a file named script.js for automatic inclusion in the main template for the site.

Keep your fi les organizedTo keep your theme directories clean, place related tpl.php fi les into relevant subdirectories. If you have a lot of images, you may also want to put them into a

subfolder.

WordPress

WordPress is a popular blogging tool that can be extended to create basic Web sites. Like Drupal, it has a rich developer and user community base and offers many plugins to extend the core framework. WordPress operates best when using a blog-style narra-tive to organize its pages.

Like Drupal 6, WordPress uses many smaller component fi les for its templates; however, the structure of a WordPress theme and the structure of a Drupal theme are quite different. To convert a WordPress theme to Drupal, you will need to combine some fi les and to split others into smaller components. WordPress will often use a function (ending with parentheses) to store the same kind of information that Drupal stores in a variable (starting with a dollar sign). These differences arise because of the rules created by the template engine used for each of the two systems.

A typical WordPress theme maps onto Drupal fi le names as shown in Table 3.1. A typical WordPress theme maps onto Drupal variable names as shown in Table 3.2.

Start with the following steps if you are given a WordPress template, but cannot easily install the blogging tool to confi rm the output:

Migrating to Drupal 6 101A

03_9780132979245_ch03_A.indd 101 1/3/12 12:51 PM

102A Chapter 3 Working with Drupal Themes

TABLE 3.1 WordPress and Drupal File Names

WordPress Drupal

index.php page.tpl.php

header.php page.tpl.php (incorporated into)

footer.php page.tpl.php (incorporated into)

404.php GUI administration function

comments.php comment.tpl.php

searchform.php search-block-form.tpl.php and/or search-theme-form.tpl.php

1. Create a new folder with the name gollum.

2. Create a new .info file that describes your new theme. Be sure to include the name of your theme, a brief description, and the Drupal core version required by this theme. Use the WordPress theme screenshot for now. You may want to replace it later if there are significant enhancements made as part of the upgrade to Drupal.

3. Put a copy of the WordPress file index.php into the gollum directory and rename it page.tpl.php.

4. Throughout the new page.tpl.php file, replace the WordPress references to external files that describe structural components with their actual file contents. For example, replace get_header(); with the contents of the file header.php and get_footer(); with the contents of footer.php.

5. Copy the sidebar.php file into the new gollum directory and rename the file to block.tpl.php. In the new file page.tpl.php, replace get_side-bar(); with a variable representing the name of the region for this sidebar. Make sure this region is also defined in the theme’s .info file (for example, gollum.info).

TABLE 3.2 WordPress and Drupal Variables

WordPress Drupal

the_title(); $title;

the_content(); $content;

next_posts_link(); Handled by Drupal’s pagination

03_9780132979245_ch03_A.indd 102 1/3/12 12:51 PM

6. Note the functions that were called from WordPress’s sidebar.php file. These functions must be matched to blocks within Drupal. Additional information on blocks is available in Chapter 4. Once your Drupal theme is enabled, you will place these blocks into the appropriate region of your new template using the administration Web interface.

7. Move the contents of index.php, which relate to individual story items, into a new template file named node.tpl.php. This information may also be con-tained in the WordPress file single.php. Check both files to ensure you have migrated all of the WordPress theme components.

8. Check the WordPress file functions.php for additional theme information that may need to be migrated to Drupal either using a text-based tpl.php file or through Drupal’s administration Web interface.

Joomla!

Joomla! is a Web-based content management system similar to Drupal. In direct com-parisons against Drupal, advocates of Joomla! will often praise its document manage-ment system and calendaring options; by contrast, Drupal has more sophisticated user permissions and multiple-site management capabilities.

Joomla! at its most basic is similar to Drupal in its theme creation. It uses a single fi le to outline the structure of the page and calls in individual variables as needed to fi ll in the gaps.

Start with the following steps if you are given a Joomla! template. In this example, the new Drupal theme is named Bilbo. Adjust this theme name to suit your needs.

1. Create a new folder with the name bilbo.

2. Create a new .info file that describes your new theme. Be sure to include the name of your theme, a brief description, and the Drupal core version required by this theme. If your theme had a screenshot, include it for now. You may want to replace it later if there are significant enhancements made as part of the upgrade to Drupal.

3. Put a copy of the Joomla! file index.php into the bilbo directory and rename it page.tpl.php.

4. Replace references to mosLoadModules() in the page.tpl.php file with a variable representing the name of the region. Make sure this region is also defined in the theme’s .info file (for example, bilbo.info).

Migrating to Drupal 6 103A

03_9780132979245_ch03_A.indd 103 1/3/12 12:51 PM

104A Chapter 3 Working with Drupal Themes

5. Create the blocks within Drupal that will replace the output of the mosLoad-Modules functions in the old Joomla! Web site. Once your theme is enabled you will place these blocks into the appropriate region of your new template using Drupal’s administration Web interface.

6. Move the contents of the Joomla! template file named index.php, which relate to individual story items, into a new Drupal template file named node.tpl.php.

7. Update Joomla!-specific variables to their Drupal equivalents (for example, the variable for the template directory becomes $directory in Drupal).

8. Move logic-based PHP scripting to the file template.php. Additional infor-mation on how to use template.php is included throughout each of the chapters of this book, including those focusing on page variables (Chapter 4) and content variables (Chapter 5).

The principles behind good design allow you to map functionality across different content management systems. Through careful examination of any theme, you should be able to map its essence into Drupal, even though the frameworks may differ signifi -cantly. If your specialty is Drupal and you are asked to convert a theme from another CMS, be sure to ask for the original theme fi les as well as the rendered HTML output for several pages (and with differing navigation depths). Converting an HTML page to a Drupal theme can be easier than trying to understand the construction of a theming system with which you have little or no experience.

Summary

Creating a simple Drupal theme can be very easy. When you are armed with the funda-mentals of how to create a Drupal theme, it becomes much easier to make Drupal look however you want. In this chapter, we walked through the following tasks:

• Finding themes

• Installing prebuilt themes

• Customizing settings in the Web-based administration area

• Creating new themes

• Using starter kits to create new themes

03_9780132979245_ch03_A.indd 104 1/3/12 12:51 PM

• Adding new theme settings that can be customized from the theme adminis-tration screen

• Migrating other content management system themes to Drupal 6

This chapter has laid out the skeleton of a Drupal theme. Being organized and using good coding practices will allow you to easily move from simple layouts to the more complicated user interactions described later in this book.

Summary 105A

03_9780132979245_ch03_A.indd 105 1/3/12 12:51 PM

This page intentionally left blank

Index

419A

AAccess control, 227A

�creating roles, 227A�granting and revoking permissions, 228A–229A�at theme level, 229A–231A

Access Forbidden message, 280AAcquia Marina theme, 115A.addClass method, 327AAdjacent sibling selector, 192AAdmin Links module, 213AAdmin Menu module, 261A–263AAdmin role module, 231AAdministration area, 388A

�making changes from, 31A–32A�sections of, 388A–389A

Administrative interface�control panels, 266A–268A�creating, 252A–256A�creating menus for, 257A–259A�custom screens for, 270A–279A�deploying menus for, 259A–260A�modules for, 262A–269A�RootCandy, 253A–256A�task-based navigation for, 256A–257A�theme for, 252A–253A

Administrative templates, 15AAdvertising, on Web pages, 15A.after method, 331AAHAH, 358AAJAX, 285A, 313A, 337A, 338A, 349A$.ajax function, 341A–342AAkismet, 243AAlphabetical organization, 12AAmadou theme, 75A.animate function, 334A–335AAnimation, using jQuery, 335A–337AAnonymous functions, 303A–305AAnonymous users, 36A–37AApache, 382A–383A.append method, 331A

.appendTo method, 332Aapply, 307A, 308Aarchive list, 177AArgument, defined, 270AArray data type, 290AATCK starter kit, 94A.attr method, 327AAttributes methods, 320A, 327A–329AAttributions setting, 52AAuthenticated users, 37A

BBackground images, on forms, 188A–191ABanners, customizing, 97A–99A$base_path variable, 111ABasic starter kit, 94ABazaar, 35A, 71A.before method, 333ABeginning starter kit, 94Ablock.tpl.php, 108ABlocks

�creating, 124A�customizing markup of, 125A–126A�dynamic and static, 38A�editing, 213A–216A�and menus, 40A�types of, 124A

Blog, defined, 9ABlog content type, 6ABlog module, 235A–236ABlueprint CSS, 68ABlueprint starter kit, 94ABody:, 158A$body_classes variable, 101A, 111A–112A, 136A

�altering, 136ABolg theme, 88ABook content type, 6ABoolean data type, 290ABoolean operators, 291ABreadcrumbs, 113A

14_9780132979245_Index.indd 419 1/6/12 9:55 AM

420A Index

Browser Cam, 62ABrowser testing tools, 60A–65ABrowsershots, 63A–65AButtons

�enabling, 370A–372A�updating, 372A–374A

Ccall, 308ACamel case, 289ACAPTCHA, 241A–242ACAPTCHA pack, 241ACAPTCHA Riddler module, 242ACategories, 38ACCK (Content Construction Kit) module, 36A, 42A

�installation of, 43A–44A�and page appearance, 173A�using, 44A–45A

Chaffer, Jonathan, 342AChaining, in jQuery, 326Acheck_markup, 160Acheck_plain, 160A, 226AChronological organization, 9A–10AClasses, 298AClean starter kit, 94A.click method, 323AClosures, 306AColor, on forms, 186A–187AColor module, 77ACommas, in JavaScript, 297A$comment variable, 153AComment closer module, 242A–243AComment content type, 6Acomment.tpl.php, 231A$comment_count variable, 153Acomment-folded.tpl.php, 232Acomment-wrapper.tpl.php, 232AComments

�adding user identity to, 234A–235A�displaying, 231A–232A�information about, 153A�in JavaScript, 294A–295A

comments_recent list, 177AComponent, JavaScript

�compatibility of, 353A�data-source agnosticity of, 374A–376A�encapsulation of, 354A–355A�example of, 355A–374A�fl exibility of, 354A�reusability of, 354A�speed of, 355A�using plugins to create, 377A–380A

console.log(), 291AConTemplate, 35A

Content�accessing, 158A–160A�delivery of, 141A–149A�describing, 2A, 4A�displaying, 3A, 5A�information about, 152A�organization of, 8A–13A�status of, 153A�storage of, 5A–7A�user-generated, 235A–239A

$content variable, 110A, 112A, 152A�data in, 160A�going beyond, 155A–156A

Content fields, 5A, 8A�private, 247A–248A

Content Management, 389AContent module, 44AContent Permissions module, 53A, 207AContent types, 5A, 7A, 36A, 42A

�adding fi elds to, 46A–48A�changing, 6A�custom, 44A–45A�extending, 46A�metadata in, 45A�page templates for, 137A–138A�settings of, 52A–53A

Control Panel module, 266A–269AControl panels, 266A–268A

�adding images to, 269A�theming, 268A–269A

Control structures, in JavaScript, 292A–293A$created variable, 151ACreative Commons, 18A, 74ACrochetMe, 12A

�example pages from, 12A, 17A, 18A, 146A, 147ACron, 70A–71ACSS (Cascading Style Sheets), 19A, 24A

�media types of, 142A�print-friendly pages in, 142A–146A�using, 66A�using on front page, 91A–92A

.css method, 328ACSS descriptors, 24ACSS methods, 320A, 328A–329ACSS selectors, 189A–190A

�advanced, 191A–192ACSS Zen Garden, 19ACustom Error module, 281A–283ACVS (Concurrent Version System), 35A, 71A

DData types, 289A–290ADatabase, creating, 385A$date variable, 152A

14_9780132979245_Index.indd 420 1/6/12 9:55 AM

Index 421A

Date module, 44ADebugging

�displaying result of, 291A�in Internet Explorer, 371A

demo.info, 399A–400Ademo.module module, 397A–399Ademo-module folder, 397A

�fi les in, 397A–400ADescription, of site, 2A–3ADevel generate module, 58ADevel module, 43A, 57A

�components of, 57A–58ADevel node access module, 58ADevelopment server, 381A–383A

�under Linux, 382A–383A�under Mac OS X, 382A–383A�under Windows, 382A

Digg, 12A$directory variable, 111ADisplay calendar, 9A–10ADisqus, 234A–235ADocument root, configuring, 383A–384ADollar function, 316A–318A

�calling, 318A–319ADollar sign, use of, 288A, 343A–344ADOM (document object model), 286A, 311ADot notation, 322ADrop-down menus, 118ADrupal

�admin area of, 388A–389A�best practices in, 34A�browser tools working with, 60A–65A�confi guring, 386A–389A�converting HTML to, 104A�converting Joomla! to, 103A–104A�converting WordPress to, 101A–103A directory structure of, 33A�downloading, 385A�function of, 32A�hurdles in installing, 385A, 386A�installing, 385A–388A�installing modules for, 390A�integration of JavaScript with, 287A, 345A–377A�path of, 33A�setup of, 381A–384A�site setup for, 386A

Drupal 5.x, upgrading to 6.x, 99A–100ADrupal 6.x

�creating theme in, 100A–101A�migration to, 100A

Drupal API, 69ADrupal page

�content of, 112A–113A�creating variables for, 113A–115A

�elements of, 107A–109A�general utility variables in, 109A, 111A�menus in, 116A–120A�modifying variables in, 115A�navigation of, 115A–120A�page metadata in, 109A, 111A�site identity of, 109A, 112A�sitewide variables of, 109A–110A

drupal_add_js, 346A–349Adrupal.attachBehaviors, 358Adrupal_json function, 351ADrupal.org, 18A

�registering on, 74A�theme directory of, 75A

Dynamic blocks, 38A

EEasing, 335AEditing

�blocks, 213A–214A, 215A–216A�screens, 212A

Effects methods, 321AElement inspector, 61AError messages, 113A, 279A–281A

�custom, 281A–283AEscape character, 290AEvents methods, 320A, 321A–327AExclamation point, use of, 169A

FFAPI, 201A–210Afavicon.ico, 84AFCKEditor, 195A$feed_icons variable, 110AField display, 49A–50AField order, 49AField types, 42Afield_extratext, 158AFieldGroup module, 50A–51AFields

�adding, 46A–48A�content, 5A, 8A

FileField module, 44AFiles, adding, 346A–348A.filter method, 330A.find method, 330A.findTarget method, 367A–370AFirebug, 60A–61A, 186A, 189A, 287A, 298AFirst pseudo-element, 192AFixed design, of page, 16AFlexible 2 starter kit, 94Aflexifilter module, 238AFlickr, 170A, 172A–175A, 195A

14_9780132979245_Index.indd 421 1/6/12 9:55 AM

422A Index

Fluid design, of page, 16A$footer variable, 92A$footer_message variable, 92AFooters, 92A–93Afor loop, 292Aforeach statement, 292AForm API (FAPI), 201A–210Aform_id, 205AForms

�altering fl ow of, 211A–212A�background images on, 188A–191A�changing display text in, 206A–207A�changing sitewide, 201A–204A�changing specifi c forms, 205A–206A�changing widgets in, 209A–210A�color in, 186A–187A�creating, 184A�enhancing, 193A–195A�facilitating input on, 187A–188A�multiple-page, 210A–211A�processing of, 184A–185A�removing fi elds from, 207A–209A�Rich Text editing of, 195A–197A�style sheets for, 185A–186A

Forms API, 192AForum content type, 6AForum module, 236A–237AFoundation starter kit, 94AFramework, defined, 31AFramework starter kit, 94AFree tagging, 10Afreelinking module, 238A$front_page variable, 112AFront page

�adjusting defaults for, 165A–166A�content teasers on, 86A–87A�customizing, 85A–88A, 130A�multiple-node, 87A–88A�single “welcome” node, 85A–86A�views on, 130A

frontpage list, 177AFunction data type, 290AFunctions, JavaScript, 295A, 302A

�anonymous, 303A–305A�calling, 307A–309A�scope of, 305A–306A

GGallery module, 175A–176AGarland theme, 94AGeneral Public License (GPL), 18AGeneral utility variables, 109A, 111AGenesis starter kit, 94A

Ginger Press example page, 11AGlobal settings, 83A–84AGlobal variables, 289Aglossary list, 177AGordon, Charlie, 239AGraphical headers, changing, 140A–141AGrids, 67A

�using, 120A–123AGuided tasks, 22A

HHandheld devices, designing for, 147A–149AHaughey, Matt, 183A$head variable, 111A$head_title variable, 111AHear the North example page, 122A$help variable, 113A, 279AHelp section, 389AHICK Tech example, 142A–144AHierarchies, of taxonomies, 39AHooks, 41A–42A, 350AHorizontal Scroller example component,

355A–356A�bootstrapping, 364A–365A�buttons in, 370A–374A�compatibility of, 374A–375A�functionality of, 361A–364A�integration with Drupal, 377A�markup of, 357A–360A�skeleton of, 356A–357A�slider in, 358A–370A

horizscroll folder, 404A�fi les in, 404A–415A

horizscroll.css, 412A–415Ahorizscroll.html, 410A–412Ahorizscroll.js, 404A–410Ahorizscroll-datasource folder, 404A

�fi les in, 404A–415A.htaccess, 385A.html method, 329AHTML pages, 90A

�converting to Drupal, 104A�structure of, 311A–312A

html.js, 373Ahttpd.conf, 383AHunchbaque starter kit, 94A

I$id variable, 152Aif statement, 292AImage Assist module, 174A, 199A–200A

�use with TinyMCE, 200A–201A

14_9780132979245_Index.indd 422 1/6/12 9:55 AM

Index 423A

Image Cache module, 172A, 177AImage module, 171A, 173A–175A

�use with TinyMCE, 200A–201AImageAPI module, 176AImageField module, 44A, 48A, 57A, 171A,

176A–177AImages

�adding to Web page, 170A�background, 188A–191A�choosing, 171A�galleries of, 175A–176A�offsite hosting of, 172A–173A

IMCE module, 201Ain_array, 230Aindex.html, 391A–396Aindex-input.html, 396A–397AInsert methods, in jQuery, 330A–333A.insertAfter method, 332A, 333A.insertBefore method, 332AInteraction, 20A–21A

�guided tasks, 22A�user satisfaction, 21A–22A

Interface components, 14A–16A�choosing, 76A–77A

Internet Explorer�debugging in, 371A�developer tools of, 62A

$is_admin variable, 111A, 153A, 208A$is_front variable, 111A, 154A

JJavaScript

�adding to Drupal page, 346A–349A�control structures in, 292A–293A�data types in, 290A�and DOM, 286A, 311A. See also jQuery.�functions in, 303A–309A�inline, 349A�interacting with, 24A–25A�libraries for, 343A–344A�object orientation in, 293A–303A�operators in, 291A–293A, 302A�running code in, 287A–288A�server-side integration with Drupal, 345A–377A�syntax characteristics of, 287A�using, 69A�using with Drupal, 285A�using on front page, 91A–92A�variable declaration in, 288A–289A

Joomla!, 103A–104AjQuery, 69A

�animation using, 334A–335A�chaining in, 326A�and DOM, 318A–319A

�Drupal modules in, 379A–380A�to execute code on page load, 314A–318A�functions of, 286A�helper functions of, 336A–337A�plugins for, 342A–343A, 377A�purposes of, 312A–313A�selector support in, 319A�setting up, 313A–314A�using, 320A–334A

jQuery UI, 343A, 379A–380AjQuery Update module, 379AjQuery.each, 337AjQuery.extend, 336A–337AjQuery.getJSON method, 340A–341AJSON (JavaScript Object Notation), 337A–338A

�creating object, 351A–353A

Ll() function, 226ALa, Nick, 69ALAMP, 382A$language variable, 101A, 111ALayout, 14A–15A$layout variable, 101A$left variable, 110ALexical scope, 305ALinear organization, 10ALinks, 158A

�creating, 226A$links variable, 151A, 163AA List Apart, 66A.load function, 339A–340ALocal variables, 289A.log function, 343A$logged_in variable, 111A, 152A, 207A–208A$logo variable, 112A

MMacro module, 58AMaintenance, system, 70A–71AManipulation methods, 321A, 330A–333AMember-only sites, 244A–246AMemory Garden Retreats theme, 96AMenu callback handlers, 349A–351AMenus, 40A–41A

�adding items to, 116A�components of, 118A�drop-down, 119A�theming, 118A–119A

Messages, types of, 113A$messages variable, 113A, 279AMicrosoft Visual Web Developer, 371A$mission variable, 112A

14_9780132979245_Index.indd 423 1/6/12 9:55 AM

424A Index

Mobile theme, 147A–149Amodule_exists, 230AMollom, 243AMonty Python, 240A.mouseover method, 322AMultiple-page forms, 210A–211AMySQL, 382A, 383A

NNaming

�conventions, 41A–42A�of theme, 88A–89A

Navigate module, 264A–266ANavigation, 110A, 115A

�and menus, 115A–119ANew content, viewing, 271A–274ANewswire theme, 115A960 Grid, 67A, 68ANode

�components of, 41A�customizing entry points to, 177A–181A�defi ned, 5A, 36A�required fi elds in, 186A

$node variable, 152A�accessing content in, 158A–160A�data in, 159A�understanding, 154A–158A

$node_url variable, 151ANode Form module, 193A–194ANode template, 150A

�changing defaults in, 163A�creating, 151A�creating variables in, 161A–163A�replacing content in, 163A–164A�using, 151A–160A

Node types. See Content types.node_revisions table, 35Anode.tpl.php, 108A, 109A, 150A, 153A–154ANodeaccess module, 246A–247Anodecontenttypename.tpl.php, 150ANumber data type, 290ANumbers, in JavaScript, 294A

OObject data type, 290AObjects, JavaScript, 293A–295A

�adding keys to, 297A–298A�defi ning, 296A–298A�extending, 301A–302A�inspecting contents of, 298A�using prototypes to create, 299A–300A

Offline page, custom, 130A–132A.offset function, 366A, 367A.one method, 323AOpen Source Web Design (OSWD), 20AOpera Web Standards Curriculum, 23A, 66AOperators, in JavaScript, 291AOption Widgets module, 44AOrphan images, viewing, 274A–279A

P$page, 169APage content, 110A, 112A–113APage content type, 6A, 36APage design, 14A–15A, 28A

�fi xed vs. fl uid, 16A�impact of small changes on, 28A

Page metadata, 109A, 111APage Not Found message, 282APage template, 89A–91A

�activating, 132A–133A�changing, 128A–132A�for content types, 137A�for views, 136A

page.tpl.php, 108APageroute module, 211A–212APagers, 41APalantir, 34A–35AParameters, defined, 270AParent items, 40APermissions, 36A–37A, 228A–229A

�setting, 53APermissions cache, rebuilding, 245A–246APersonal themes, 81A–82APhotos, sources for, 20APHP, 24A

�converting to JSON, 338A�inside blocks, 125A�inside HTML, 93A�inside templates, 114A�using, 68A

phptemplate, 89Aphptemplate_callback(), 100A$picture variable, 152APlus sign, in JavaScript, 302APoll content type, 6APopularity-based organization, 12A–13APost settings, 52APostgreSQL, 383A<pre> tags, 156A.prepend method, 331A.prependTo method, 332A

14_9780132979245_Index.indd 424 1/6/12 9:55 AM

Index 425A

Preprocess functions, 214A–215Apreprocess_block, 215APreprocessing, 113A–114A$primary_links variable, 110A, 115APrint-friendly pages, 141A–142A

�CSS, 142A–145A�templates for, 145A–147A

print_r, 156APrivate

�content fi elds, 247A–248A�member-only sites, 244A–245A�Web site areas, 244A

Profile�adding information to, 225A–226A�creating, 220A–222A�theming, 222A–224A

promoted to front page option, 87A–88AProfile module, 220A–221A$promote variable, 154APrototype/Scriptaculous, 343A–344APrototypes, 298A–299A

�objects created by, 299A–300A

R$readmore variable, 152ARebuilding permissions cache, 245A–246AreCAPTCHA module, 241ARecipe module, 239ARegions, 37A

�adding, 121A–123A�defi ning, 92A�using, 120A–121A

Release forms, 20A.remove method, 333A.removeClass method, 328ARendered page, 90A.replace method, 333AReports item, 389AReuse, of styles, 23AReverse chronological order, 9ARevision control, 70A–71ARich Text editing, 195A–201A$right variable, 110ARoles, 227A–228ARootCandy theme, 253A–256A

SScope, of function, 305A–307AScreenshots, 63A, 93Ascript.js, 92AScripting languages. See JavaScript; PHP.$scripts variable, 111A

scrollToItem function, 365A–367ASearch module, 126A–128A$secondary_links variable, 115A, 117ASemicolons, in JavaScript, 296ASettings storage, 347A–349AShortcut icon, 84ASite building, 386ASite configuration, 387A–388ASite identity, 109A, 112A$site_name variable, 110A, 112A$site_slogan variable, 112Askeleton.css, 403A–404Askeleton.html, 402A–403Askeleton.js, 400A–402ASlider, creating, 358A–361ASpam, 240A

�fi ltering of, 243A–244A�minimizing, 241A–243A

sparkline folder, 415A�fi les in, 415A–417A

sparkline.html, 415A–417Asparkline.js, 417ASparklines plugin, 377A–379AStarter kits, 94A–95AStarter themes, 94AStatic blocks, 38AStatic scope, 305A$status variable, 154AStatus messages, 113A$sticky variable, 154A.stop method, 335AStory content type, 6A, 36AString data type, 290AStyle sheets, 91A–92A, 185A–186A

�degradation of, 373Astyle.css, 92A$styled summary variable, 169A$styles variable, 111A.submit method, 326A$submitted variable, 152ASubversion, 35A, 71ASummary, creating, 166A–168Aswitch statement, 292ASystem maintenance, 69A–70A

�revision control, 70A–71A�task scheduling, 70A

Tt() function, 227A, 232A$tabs variable, 113A, 154A$tabs2 variable, 113ATask scheduling, 70ATask-based organization, 13A

14_9780132979245_Index.indd 425 1/6/12 9:55 AM

426A Index

Taxonomies, 38A�hierarchies of, 39A

Taxonomy Access Control Lite module, 244A�installing, 245A

Taxonomy templates, 138A–140Ataxonomy_term list, 177A$teaser variable, 152A, 153A, 168ATeasers, 86A–87A

�adjusting settings for, 165A–166A�distinguished from summaries, 166A–167A�templates for, 168A–169A

Teleport module, 263A–264Atemplate folder, 391A

�fi les in, 391A–397Atemplate.php file, 34A

�streamlining, 202Atemplate-skeleton folder, 400A

�fi les in, 400A–404ATemplates

�changing, 129A–134A�customizing, 18A�design resources for, 17A–19A�interface components in, 15A–16A�space allocation in, 16A�Web resources for, 19A–20A

Tendu starter kit, 94ATerms, 39A$terms variable, 152ATernary operator, in JavaScript, 293ATesting tools for browser, 60A–65A.text method, 329AText files, working with, 35AText module, 44ATextimage module, 172ATheme developer module, 58Atheme function, 226ATheme Garden, 18A, 74A–75ATheme registry, caching system of, 35Atheme-settings.php, 96A–98ATheme-specific settings, 84A–85AthemeName.info, 100AThemer info widget, 58A–59AThemes

�adding JavaScript to, 347A�administration of, 82A–88A�assigning, 129A�banners for, 99A�components of, 79A�custom settings for, 97A–98A�customization of, 108A–109A�default, 79A�defi ned, 32A

�distribution of, 93A�enabling of, 79A–80A�global settings for, 83A–84A�initializing, 89A�installation of, 78A–79A�libraries of, 77A�naming of, 88A–89A�page template for, 89A–91A�personal, 81A–82A�regions in, 92A–93A�starter, 94A�strategies for, 33A–34A�templates for, 74A�upgrading Drupal version of, 100A–101A

Thumbnails, 93ATinyMCE, 195A–196A

�appearance of, 199A�buttons and plugins for, 198A–199A�cleanup and output for, 199A�confi guring, 196A–199A�CSS settings for, 199A�extending, 201A�images in, 199A–201A�installing, 195A–196A�versions of, 200A�visibility settings, 197A

$title variable, 110A, 112A, 152A.toggleClass method, 328AToilet Birthdays example page, 4A, 172AToken module, 44ATopical organization, 11A–12Atpl.php files, 34A, 101Atracker list, 177ATraversing methods, 321A, 330ATrillium Healing Arts Centre example page, 2A

�components of, 3ATufte, Edward, 377A$type variable, 152A

U$uid variable, 152A.unbind method, 323A–324AUnpublished content, viewing, 279A–279AURL alias, 133A–134A

�and Drupal, 134A–136AUser management, 389AUser satisfaction with Web page, 21A–22Auser/1A account, 37Auser-picture.tpl.php, 223Auser-profile.tpl.php, 224Auser-profile-category.tpl.php, 224Auser-profile-item.tpl.php, 224A

14_9780132979245_Index.indd 426 1/6/12 9:55 AM

Index 427A

user_access, 230Auser_is_logged_in(), 230AUsers

�access control, 228A–232A, 244A–248A�administrator privileges for, 231A–232A�anonymous, 36A–37A, 219A�authenticated, 37A�content generated by, 235A–239A�information about, 153A�profi les of, 220A–222A�role in creating Web site, 28A

VVanDyk, John, 398AVariables

�creating, 113A–115A�in JavaScript, 288A–289A�modifying, 115A�prefi x for, 288A�resetting, 115A�scope of, 289A�unused, 115A

Version control, 70A–71AVertical Tabs module, 192A–193AVideos, adding to form, 195AView

�creating, 57A�page template for, 136A

View mode, 113AViews exporter, 53AViews module, 43A, 53A

�administrative use of, 271A–272A�components of, 54A–55A�templates in, 178A–181A�using, 54A–57A, 177A–181A

ViewsUI, 53A�use and disabling of, 54A

Virtual hosts, 383A–385AVocabularies, 39A

WW3C Markup Validation Service, 66AWarning messages, 113AWay Back Machine, 28AWeb Developer’s Toolbar, 62AWeb page(s)

�coding of, 22A–26A�components of, 3A�content of, 2A�Drupal. See Drupal page.

�guided tasks on, 22A�images on, 170A–173A�interaction with, 20A–22A�internal path for, 132A�layout of, 15A–17A�private, 244A–248A�regions of, 16A–17A

Web site�client role in, 27A–28A�designer’s role in, 26A–27A�identifying mark for, 15A�planning of, 25A–30A�programmer’s role in, 27A�searching, 126A–128A�users of, 28A, 36A–37A

Webform module, 211AWeight, 40AWelcome page, 85Awhile statement, 292AWikis, creating, 237A–239Awikitools module, 238AWordPress, 101A–103A.wrap method, 333A

XXAMPP, 382AXHTML, 23A

�structure of, 311A–312A�using, 66A, 89A

XmlHttpRequest, 337A

YYahoo! User Interface (YUI), 68AYAML CSS Framework, 68AYUI Grids CSS, 68A

Z$zebra variable, 153AZen starter kit, 94A

�described, 95A�using, 96A–97A

Zen theme, 17A, 61A, 84A, 96A, 98A, 114A, 115A, 121A, 136A, 212A–217A, 232A, 237A

Zotero, 77A

14_9780132979245_Index.indd 427 1/6/12 9:55 AM

This page intentionally left blank

Drupal’s BuildingBlocks

The Developer’s Library Series from Addison-Wesley provides

practicing programmers with unique, high-quality references and

tutorials on the latest programming languages and technologies they

use in their daily work. All books in the Developer’s Library are written by

expert technology practitioners who are exceptionally skilled at organizing

and presenting information in a way that’s useful for other programmers.

Developer’s Library books cover a wide range of topics, from open-

source programming languages and databases, Linux programming,

Microsoft, and Java, to Web development, social networking platforms,

Mac/iPhone programming, and Android programming.

Visit developers-library.com for a complete list of available products

Developer’s Library Series

Drupal’s BuildingBlocks

Upper Saddle River, NJ • Boston • Indianapolis • San FranciscoNew York • Toronto • Montreal • London • Munich • Paris • Madrid

Capetown • Sydney • Tokyo • Singapore • Mexico City

Quickly Building Web Sites with CCK, Views, and Panels

Earl MilesLynette Miles

with Emma Jane Hogbin and Karen Stevenson

Many of the designations used by manufacturers and sellers to distinguish their productsare claimed as trademarks. Where those designations appear in this book, and the pub-lisher was aware of a trademark claim, the designations have been printed with initial capi-tal letters or in all capitals.

The authors and publisher have taken care in the preparation of this book, but make noexpressed or implied warranty of any kind and assume no responsibility for errors or omis-sions. No liability is assumed for incidental or consequential damages in connection with orarising out of the use of the information or programs contained herein.

The publisher offers excellent discounts on this book when ordered in quantity for bulk pur-chases or special sales, which may include electronic versions and/or custom covers andcontent particular to your business, training goals, marketing focus, and branding interests.For more information, please contact:

U.S. Corporate and Government Sales(800) [email protected]

For sales outside the United States, please contact:

International [email protected]

Visit us on the Web: informit.com/aw

Library of Congress Cataloging-in-Publication Data

Drupal’s building blocks : quickly building web sites with cck, views,and panels / Earl Miles ... [et al.].

p. cm.Includes bibliographical references and index.ISBN 978-0-321-59131-9 (pbk. : alk. paper)

1. Drupal (Computer file) 2. Web sites—Authoring programs. 3. Website development. I. Miles, Earl.TK5105.8885.D78D77 2010006.7'8—dc22

2010043527

Copyright © 2011 Pearson Education, Inc.

All rights reserved. Printed in the United States of America. This publication is protected bycopyright, and permission must be obtained from the publisher prior to any prohibited repro-duction, storage in a retrieval system, or transmission in any form or by any means, elec-tronic, mechanical, photocopying, recording, or likewise. For information regardingpermissions, write to:

Pearson Education, Inc.Rights and Contracts Department501 Boylston Street, Suite 900Boston, MA 02116Fax: (617) 671-3447

ISBN-13: 978-0-321-59131-9ISBN-10: 0-321-59131-3Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana.First printing, December 2010

AssociatePublisherMark L. Taub

Executive EditorDebra WilliamsCauley

DevelopmentEditorMichael Thurston

Managing EditorJohn Fuller

Full-ServiceProductionManagerJulie B. Nahil

ProjectManagementLaurelTech

Copy EditorJill E. Hobbs

IndexerJack Lewis

ProofreaderCharlesRoumeliotis

Technical ReviewersJen Lindner Andy Wilson Chris Hanson Clay Robeson

PublishingCoordinatorKim Boedigheimer

Interior and CoverDesignerGary Adair

CompositorLaurelTech

To “Sprout” and “Bud”

This page intentionally left blank

ForewordThere was a time, in the 1950s, when to be a computer programmer you had to besomething of an electrical engineer. You had to be handy with wire cutters and strippersand be willing to get your hands dirty—literally. That all changed over the decades, andprogramming a computer became a simple feat by contrast. Still, it remained the domainof only a few people with the proper education and technological sense. It was theadvent of microcomputers and the Internet that made the world of technology moreaccessible, or at least began the process of attracting more people.

It was that time and those elements—that first major wave of public inclusion—thatcalled for easier methods and for better tools for programming, for making use ofcomputers, and for communicating information throughout the world.

It seems that each decade—perhaps not exactly in 10-year increments—brings with ita new wave of technology that makes the use and manipulation of technology accessibleto more people. Each period begins with only people of certain technology prowessbeing able to participate fully. But in time the demand becomes so great, and the desiresof the greater community so intense, that new innovations are achieved and new waysare determined in which more people can be part of the creation process and not just beon the receiving end.

It was just 15 years ago or so that Web design required an in-depth understanding ofHTML, skills in network configuration, and the ability to program using less-than-intuitiveprogramming languages to be able to do more than create a few flat Web pages. To be ableto create forms, allow users to enter information themselves on a site, and provide many ofthe features that are commonplace today required the advanced and diverse programmingskills of a Web developer—not to mention a sense of design, an understanding ofmarketing, and good writing abilities. So, many sites were either poorly constructed or elsewere the result of a heavily orchestrated organization that employed many people fromdiverse backgrounds. Web design was simply inaccessible for most people andorganizations.

That has all changed as well and is continuing to change. We’re in the middle of anew period of accessible technology, it seems. Drupal is changing the way Web sites arebuilt. While Drupal can be used as a Web programming framework, it doesn’t have to be.Unlike many other Web design tools, you don’t have to be a programmer to build a Website with Drupal.

In the Drupal world, many people build Web sites very easily. You just decide whatyou want on your Web site—text, photographs, a blog, places for visitors to comment, a feed from your Twitter account, and many, many other things—and then download themodules you need based on your wish list (you can have all that you wish for now),install each module, do a bit of configuring through your Web browser (mostly pointingand clicking, with the occasional typing of content), and you’re done. Zero programmingis required. It’s that easy.

The Drupal community has created thousands of modules, all freely available from thedrupal.org Web site. It’s a credit to the collective efforts of thousands of smart peopleworking together for years, not only for their own interests, but even more so for thebenefit of others. Each module alters and extends Drupal’s core capabilities and adds newfunctionality to a Drupal site. Owing to the vast amount of modules available from theDrupal community, the number of distinctly different sites that can be built using Drupalis unlimited, and the number that have already been built using Drupal is extensive. Thespeed at which sites can be assembled using Drupal and Drupal modules is surprisingand unmatched. Not a single proprietary content management system has the depth andbreadth of Drupal—not to mention that it’s free.

Nevertheless, two contributed modules stand out from the rest: Content ConstructionKit (CCK) and Views. Not only are they the most popular modules, but they are alsotwo of the most flexible modules. I have repeatedly been surprised by how Webdevelopers use Drupal, and what they build using CCK and Views. More than once, I’vebeen shown “new tricks” of what can be done with CCK and Views without a singleline of programming. The world of CCK and Views is an interesting one. The true depthand richness of these two modules have been mastered by only a few people, becauseultimately the limits of what you can do with these modules has more to do with thedata provided to them than it has to do with the capabilities of the site builder. ThePanels module, while not standing out quite as strongly as Views and CCK, allows sitebuilders the opportunity to tune their sites more carefully to look and feel the way theywant. It gives them large amounts of control and organization, again without needing towrite a single line of code. It, too, has allowed surprising systems with only a few tricks.

Behind the code that makes these modules work is a strong community of committedvolunteers. One of these people is Earl Miles, a coauthor of this book. As an activemember of the Drupal community for many years now, he has contributed a great deal tothe direction of Drupal. More specifically to the topic of this book, he is a keycontributor to CCK and the principal author of Views and Panels. I cannot think of abetter person to write about these particular modules. Coauthor Lynette Miles, incontrast, is not a developer at all, and yet these modules have allowed her to contribute tothe Drupal project by providing support for the usage of these modules both ondrupal.org and in IRC. Her knowledge of the questions people ask when learning to usethese modules is instrumental in understanding how to explain these sometimes difficultconcepts to users.

Even if you’re already a seasoned user of CCK, Views, or Panels, I have no doubt thatthis book will provide you with several new techniques and methods for getting themost out of these extremely essential modules. It certainly has for me.

Dries BuytaertFounder and project lead of Drupal,

CTO of AcquiaOctober 2010

viii Foreword

PrefaceDrupal is an open source software package that is offered for free to download, modify,and use. It has been implemented by thousands of people around the world and is usedby millions of people daily as the basis for discussion Web sites, community portals,corporate intranets, e-commerce Web sites, vanity Web sites, resource directories, imagegalleries, podcasts, and more. By choosing to use Drupal, you are accessing not only anaward-winning Web platform, but also its vibrant community.

Often referred to as “The Big Three,” the Content Construction Kit (CCK), Views,and Panels modules have fundamentally changed the way developers, site builders, anddesigners create Drupal Web sites—and yet they are all contributed modules. In thisbook, the core contributors to these three suites of modules teach you how to buildbetter Web sites. The modules described are widely considered essential modules that willbe installed on almost every site. They allow for a level of customization that isunparalleled in the market, and are a key reason that Drupal is being chosen over itscompetition.

The book assumes you are familiar with how to install Drupal and enable modules.Web developers and administrators of Drupal Web sites are the target audience, althoughthe book is written so that devoted Drupal enthusiasts can fully customize their sitesusing the information provided here.

Part I—Content Construction KitContent Construction Kit is a module that allows you to define the data that makes upyour site’s content types. It lets you add new fields chosen from a variety of field types,such as text, numbers, dates, and even references to other content. It handles input formsand provides a variety of output styles for each field. Throughout the first part of thisbook, you will learn how to use CCK to customize your data objects to conform toyour needs, rather than making your needs conform to the core content types.

Chapter 1In Chapter 1, we explain the basic concepts needed to understand the powerful butcomplicated creature known as CCK, including how it came to be, how the basicDrupal structure is defined, and why the level of flexibility and customization offered bythe node system is important.

Chapter 2Expanding on the general usage of content types and fields, Chapter 2 delves into howCCK works its magic, both from an administrative user interface (UI) point of view andwithin the Drupal database itself. To do so, we explore two potential Web sites: ahomebrewer’s journal and a T-shirt sales site.

Prefacex

Chapter 3There are an extensive number of ways you can use content fields to create your Website. Understanding and using fields and helpers for those fields creates possibilities forany kind of data. In Chapter 3, we dig more into field types and consider why youmight want to use one type of field over another in your content type. We also look atsome field types that you might want to add, but that are not part of the core CCKpackage.

Chapter 4Now that your content is created, it’s time to make it look professional and easy to read.CCK does a great job of allowing you to add plenty of customized content. What itdoesn’t do as well is display the data in a fashion that is clean and nicely readable forusers. In Chapter 4, we take a look at the theme system and how CCK interacts with it.

Chapter 5CCK includes methods that PHP developers can use to create fields outside of the userinterface. This creates even more flexibility, but requires a definite knowledge of the PHPlanguage as well as familiarity with Drupal’s development style. In this chapter, we delveinto integrating CCK with other modules.

Part II—ViewsThe Views module is a powerful query builder designed to simplify the task of buildingcustom query displays. It accomplishes this feat by providing lists of all table and fieldinformation that it knows of and letting the user assemble items from these lists together.After a complete rewrite for Drupal 6, Views has a new interface with more options thanever before. With the addition of a live preview and query display, site builders can naildown their displays in a way that was previously impossible to do without makingchanges that can affect all users.

Chapter 6Drupal relies on an SQL database to store information, and it currently supports MySQLand PostgreSQL. Properly using Views requires an understanding of how the databasestores data, how it is related across various tables, and how Drupal works with thedatabase to retrieve data. This chapter is directed toward newer users and programmers.

Chapter 7In Chapter 7, we focus on the Views UI, including how each function works. We look athow each piece creates part of a query, and how the results of those queries fit into pagesand blocks. We also discuss the most important filters you may need as well as how tocreate relationships between node content that does not otherwise share information.

xx

Preface xi

RSS, styles and fields, and the Views Bonus Pack are other important topics whendetermining what you want out of your view; they are also covered in this chapter.

Chapter 8Supplying arguments to Views is one of the ways the Views module becomes even morepowerful and flexible. Relationships bring data together in new ways, and expand theinformation available to the rest of Views. Chapter 8 describes how to customize yourviews even more through the power of relationships, arguments, and filters.

Chapter 9Views can be themed just like anything else in Drupal. The Views module provides anentirely new level of classes, theming templates, and strategies over its predecessor. InChapter 9, we discuss the template files and their contents, change some CSS, and lookat how we can approach rendering data by multiple methods.

Chapter 10One of the biggest questions facing the developers of any software installation of anykind is, “How much time will each part of this application take?” Entire softwarepackages exist to measure this kind of information. For some people, optimization is thekey to a well-run and well-maintained site. For others, this issue represents a giant hassle.In Chapter 10, we provide a few suggestions as to when and why it might beappropriate to do some customization to your Views-generated queries.

Chapter 11In Chapter 11, we explore the nuts and bolts of how Views is put together—at the codelevel. You will learn about the data architecture of Views, the life cycle of a view, and itsdatabase schema. We also introduce the plugins and handlers needed to control customqueries and formatted output.

Part III—PanelsNow it’s time to really customize how you want your site to look. The Panels modulesupplies a group of standard layout templates. In this part of the book, you learn how tocreate panels that override default page layouts, explore how to theme these layouts, andget an introduction to the Panels API.

Chapter 12The core functionality of the Panels module is layout; designing the layout is whenthings start to look polished. With an understanding of Panels, administrators can create astyle that is easily applied to every page of a site, or a different style for every page.Chapter 12 provides an introduction to how Panels works.

Preface

Chapter 13In Chapter 13, we investigate the Panels UI, including how each part fits together tocreate a wide range of panels. You learn how to create your very first panel, add contentto a range of panel types, and override the core display pages for each of your site’scontent types.

Chapter 14Panels incorporates a few major features that can take you from the basics of Web sitedevelopment to real complexity. Using arguments, relationships, and contexts, you canbuild connections between pieces of content in your panel layouts.

Chapter 15We’ve come to the final steps of designing a Web site with Panels—theming. Thisdevelopment phase puts the last touches on a Web site and brings everything together.Chapter 15 covers styling that can be done from within the Panels UI. You also learn howto apply custom CSS selectors that you can hook into from your own CSS files. Prepareyourself to be amazed at the level of control Panels gives you for theming your site.

Chapter 16Once a site is built, it must be deployed and made available for use. In Chapter 16, wetouch on some of the challenges and changes that come with moving a site from testingto production. Views, Panels, and CCK all have the ability to export their structures,giving you the most leverage over site control; in this chapter, you find out how.

Part IV—AppendicesThe appendices cover a range of topics you’ll need to truly succeed with this suite ofmodules. Appendix A covers other, relevant modules you’ll want to check out whenbuilding a site with CCK, Views, and Panels. Appendix B teaches you the “best practices”for reporting an issue. Appendix C gives you an overview of the plugin classes that areavailable to programmers in the Views API.

xii

AcknowledgmentsEarl and Lynette would like to thank more people than they can possibly remember fortheir help and support during the writing and production of this book. First, our editor,Debra Williams Cauley, had much more patience than we could have asked for ordeserved. Emma Jane Hogbin was instrumental in the final push to complete this book—not to mention being generally sympathetic and otherwise all-around awesome. KarenStevenson also deserves mention for her significant contribution of the Content Construc -tion Kit API chapter. Our friends as well as cohorts in the Drupal community—Clay,Chris, Andy, and Yves—provided lots of valuable feedback about where things were good,bad, and “What in the world were you trying to say here?” We would also like to thank thetechnical and copy editors at Pearson who made sure we were up to standard and cleanedup after us; any errors are most definitely ours, not theirs. Finally, we would like to thankour family and friends, with a special “thank you” to famous writer C. E. Murphy, forbeing encouraging and offering lots of helpful advice on how to keep making progress.

About the AuthorsEarl Miles is a permanent member and founder of the Drupal Association. In 2005, Earlfound Drupal and thought it was exactly what he needed to build a Web site in his sparetime. When he found that Drupal lacked some key features, Earl ignored work for threeweeks and created the Views module, which has been instrumental in Drupal’s continuedgrowth. Earl has been active in the community, providing support, as well as posting tipsand tricks when the mood strikes him.

Happily married, Earl’s first child was born May 2007. He is an amateur writer (sci-fi fantasy) and a gamer. A lifelong programmer, he is currently employed by iO1, acompany that actively participates in the development and consumption of open sourcesoftware.

Earl’s Drupal blog is Angry Donuts (www.angrydonuts.com).

Lynette Miles has worked for 15 years in professional software technical support,mainly for Alcatel-Lucent. During that time, she has done everything from respond to customer issues via phone, email, and ticketing systems to writing and editing documentation for corporate software. She has also spent entirely too much time building and maintaining technical support knowledge bases for customers and supportteam members.

She became involved with Drupal after attending DrupalCon Brussels andDrupalCon Barcelona with her husband and becoming tired of listening to him talkabout how active his issue queue was. Since then, she has spent most of her contributingtime working with the Drupal Documentation Team and triaging the Views and Panelsqueues. She actively maintains that she is not a coder, stating, “I have people for that.”

Lynette is a gamer, a spinner, and a knitter. She has cheerfully created her own Drupalhats based on Emma Jane Hogbin’s pattern, complete with glow-in-the-dark faces. Mostof her time is spent ensuring that she and Earl’s daughter (also a DrupalCon fixture)learn the proper way to work with Drupal, “Don’t hack core!”

3Deeper into Fields

In this chapter, we’ll dig more into fields and all the detailed information for each one.We’ll discuss field types in greater depth and explore why you might prefer one type offield over another in your content type. We’ll also look at some field types that youmight want to add that are not part of the core Content Construction Kit (CCK) pack-age. And we can’t forget about dates, or special uses of fields where you want to derive avalue from other information.

Choosing Field TypesIn Chapter 2, we went through the processes of creating a new content type and addinga field to an existing content type. To this point, we’ve looked at the various data types.Most of them are straightforward, but others aren’t as obvious to a new user. This sectionprovides more information about these types, as well as field settings that come afterbasic field creation.

A key question when working with fields is, “How do I choose one field type overanother?” User and Node Reference fields are specialized enough that their use is clearlypreferable in certain situations. In many situations, the choice is obvious. For example,you wouldn’t use a Text field where an image is needed, but you might not be surewhere to use a Float type versus a Decimal. These are the absolute basic field types youneed to create specialized content for your nodes, and it is imperative that you have afull understanding of the options for each one before getting started with Web sitedevelopment using the CCK module.

When field modules other than CCK are installed, each adds a new data type, widget, andconfiguration page specific to the needs of that module—just like CCK. They all have thesame style, but the options for each one will differ. Most of the global settings for the com-puted field are specific to each data type.

In the following sections, we’ll cover use cases for the different types of fields and seewhat each field is best at.

Using TextIn our previous examples, we saw how a Text field can be used for nearly anything youwant. Text fields are the easiest to create and use. Every Web site user knows what a Textfield is and what is generally expected to be entered in those fields. Almost any alphanu-meric data and many special characters can be put into a Text field.

Plain Text fields are simple to use, and easy for users to understand. They are an excellent choice to store descriptions, names, addresses, and the like. Plain Text fields canalso be used to store numbers. If you decide to do so, however, you must carefully consider both the present and the future of the site. Text fields should not be used for storing numbers. If there is any chance that the field will ever be used to do a computation, such as determining sales tax on a purchase, then you should not use a Text field.

Other considerations must be taken into account as well. Views will give you optionsfor filtering data. Text fields are filtered differently than numeric fields; the Text type usesalphabetical order for sorting purposes. Using a Text field to store numbers also does notensure that only numbers will be stored there. Perhaps your intent is to have numericinput, but your users might enter text accidentally (or on purpose!). A Text field does notprovide validation or error checking for numeric values.

Using Numeric TypesCCK has three different field types that are best used for storing numbers: Decimal,Float, and Integer. Using one of these field types helps to future-proof your site forchanges. All of these types are similar in function, which can cause confusion whenyou’re trying to choose one for a particular functionality.

A Decimal field is ideal for storing monetary values such as prices and salaries. Itallows values to have a maximum of two places to the right of the decimal marker,which limits this type’s use for scientific notation purposes. Decimal fields allow furthermathematical calculations to be performed, so they can be manipulated and can createinformation for other fields much more easily than a Text field can. This field type alsohas settings to change which marker/fractional symbol is used as the decimal place-holder, which makes this field type more easily used internationally, as different countriesuse the fractional symbol in different fashions.

Float fields are the best option when you want to store either very small or very largenumbers. This type does not limit the number of digits before or after the decimalmarker, which makes it perfect for use in mathematical calculations.

Integer fields hold whole numbers. This field type is very useful for quantities in storeinventories or supply lists.

When you’re looking at using Views filters, numeric fields give you better options forfiltering on numbers that are greater or less than a given value. Numbers also take up lessdatabase space, and validation can easily be implemented to ensure that only numericdata is entered into the field.

40B Chapter 3 Deeper into Fields

41BChoosing Field Types

Using Node Reference A Node Reference field is a highly useful method of relating a node to one or moreother nodes. This option can be used much like an index or for a series of news stories.For example, on a clothing sales site, it could be used to link a shirt offered for sale touser-submitted pictures of that shirt being worn. Node Reference fields help to create adirect link between different nodes. You can also create a view that uses those referencesto query for specific nodes.

Consider some other uses for node references. Suppose a musician’s Web site has a listof CDs, and each CD has a group of tracks. A Node Reference field can easily handlethe relationship between artist and CD, artist and track, and CD and track. This allowssomeone visiting the artist’s Web site to easily navigate back and forth, and permits theWeb site developer to create a discography quite easily. To achieve that, you would use acontent type for artist, CD, and song, and each of those types would use a NodeReference field that refers to the other two content types. For complete navigation, theartist would link to the CD and song, the CD would link to the artist and song, and thesong would link to the CD and artist.

When linking nodes with Node Reference, each of the referring fields would need tobe created separately; Node Reference is unidirectional. When a Node Reference field iscreated, node A refers to node B, but a link from node B back to node A must then becreated if you want the navigation to be both ways. For instance, linking artist to CD isone direction; linking CD back to artist would require another Node Reference field.

Exercise 3-1Creating a Node Reference Field

Returning to our previous homebrewing example, recall that we have created the con-tent type for recipes. We also need a separate content type to keep track of the differenttimes we’ve brewed that recipe.

1. Create a new content type for the product (a batch of beer), using these values:

Field Value

Name Batch brewed

Type batch_brewed

Description Information on a batch of beer, wine, and so forth

2. Add a field to the content type.

Field Value

Field name recipe_used

Label Recipe

Field type Node ReferenceWidget type Autocomplete Text field

Chapter 3 Deeper into Fields42B

Field Value

Required Checked

Number of values 1

Content types that can be referenced Beer recipe

Figure 3-1 A node with a Node Reference field in use

Now, when you create a batch, you can type the name of a recipe into the Recipe field,and it will search the database for a name that matches what you have entered into thefield.

Node Reference is a very powerful tool when used appropriately. Think about whichpaths your users might want to follow when they are looking at content on your sitethat might not follow the traditional breadcrumb method.

Using User ReferenceThe User Reference type creates a relationship between a node and a user outside of the node author; a user’s information is also a node, but this is a relationship outside of that. User Reference is very useful for creating teams and adding players. It could be used to add a sales contact to a product, for example, or to add staff to a scheduledevent.

If you need to create a group that people belong to, User Reference can be used as a very basic way to do so. Drupal contains other modules specifically intended to create groups (such as Organic Groups: http://drupal.org/project/og). Those modules are reasonably large and rich in functionality specific to creating and maintaining groups.

3. On the next page, go down to the global settings. We want to place some restrictions on the field.

Constraining Data with Widgets 43B

Figure 3-2 Creating a reverse link with User Reference

User Reference works much like Node Reference, but uses certain types of globaluser permissions rather than node types to limit the things that can be linked to. Drupalsite administrators may create roles for the site’s users, giving or denying permission toperform actions such as creating or editing content. The basic user role is authenticateduser. A User Reference field that works with an authenticated user will allow everyavailable user with login access to be chosen as a valid value.

You can also use the final flag on the User Reference type to do a more general limiton users. Drupal users are either active or blocked (i.e., banned from access). UserReference normally would create a list from all valid accounts in a role, but if the Activeflag is checked, only active user accounts will be included in the select list or autocom-plete search. If your site has a large number of users, this can narrow down your searchtime considerably. And, much like with the Node Reference field type, users can bedefined by Views.

As noted earlier, User Reference helps you to link nodes to other users, and the availablewidgets create limits specifying what users can be linked to. The user roles limitation withUser Reference is much like the content type references under Node Reference. Your sitemay have a few roles or many, and you can choose to allow a field to reference only userswith particular permissions. You will need to define those roles for your site; only theadministrative role is available initially. You can also decide to allow only active users to bereferenced. By default, the only available settings for user status are Active and Blocked.

Constraining Data with WidgetsAs described in Chapter 2, each created field has two types of settings: settings for thatfield specific to that content type (Figure 3-3) and global settings that are used for the

The User Reference type also contains one invaluable function: It has the ability tocreate reverse links (see Figure 3-2). Using this functionality, you can establish a two-waylink between a user and a node. If you were to use this feature to add a user to an event,you would also add that event to the user’s profile page. A flag for the field is set basedon the content type; it is visible as a check box in the content type settings when youare creating or managing the field. User Reference can refer to a default value, so a newpiece of content may always have a link to a specific user.

Chapter 3 Deeper into Fields44B

Figure 3-3 Settings for a field per node type

field in that content type as well as every other content type it appears in (Figure 3-4).Widgets are also known as form elements.

Figure 3-3 shows an example of settings that can be enacted on a field within onecontent type. In this case, we are looking at a Text field, and we can limit its size and givesome help text to assist the user in filling in the field properly.

The global settings (Figure 3-4) affect the field, regardless of what content type it is in. Thus, if you use the field in more than one place, these settings will continue toapply.

Once you are sure which field type is the right one for your Web site, you have manyother options available to help you get input and determine the basic display properties.Each field type uses a widget to restrict and define the allowable values (not the Allowedvalues—that’s another setting!).

Widgets are similar to very specific formatters. They don’t determine how the field isdisplayed, but rather regulate how the content of the field itself is chosen or input. Eachfield type comes with its own set of available widgets, and each widget has deeper settings to control how it works. For example, if you want to use a number, there aremultiple options to consider depending on the situation. In theory, widgets are interchangeable: the purpose for which they are needed determines which widget is

45B

appropriate in a given situation. Following is a list of the widgets that are available withCCK at install:

n Text field: Stores any basic string of text.n Select list: Gives a choice of a prepopulated list of user-defined options.n Check boxes/radio buttons: Allow for the definition of a multiple-choice checklist

or a single-choice radio button.n Single on/off check box: Allows one check box.n Autocomplete: Allows a user to type in part of a node name, with Drupal then

attempting to fill in the rest of the field by searching through the database to findmatches.

n Multi-row text area: Creates a larger than one-line text box.

Certain widgets are available only for particular data types. Unlike with the field’s datatype, however, you can change the widget for the field later if your needs change or ifyou find that your original widget choice is not well suited to what the field really needsto do. Each widget has a group of settings as well, to further refine its usage (Table 3-1).

Figure 3-4 Global settings for a field across all node types

Constraining Data with Widgets

Chapter 3 Deeper into Fields46B

Decimal

Float

Integer

NodeReference

Text

UserReference

Text field, select list, check boxes/radiobuttons, single on/off check box

Text field, select list, check boxes/radio buttons, single on/off check box

Text field, select list, check boxes/radio buttons, single on/off check box

Select list, autocomplete

Select list, check boxes/radio buttons,single on/off check box, Text field,multi-row text area

Select list, autocomplete

Minimum, Maximum,Precision, Scale, Decimalmarker, Prefix, Suffix

Minimum, Maximum, Prefix,Suffix

Minimum, Maximum, Prefix,Suffix

Content types that can be referenced, Node/views to bereferenced

Text processing (plain or filtered text), Maximum length

User roles that can be referenced, User status thatcan be referenced

Table 3-1 Widget Types and Settings per Field Type

Field Type Available Widget Types Settings

Decimal, Float, and Integer share most of their attributes; given that they all deal with numbers, this makes a great deal of sense. The Minimum and Maximum settingsallow the administrator to set a limit on the highest and lowest values, respectively, thatcan be entered for the field. The Precision setting designates how many total numbersfor this field will be stored in the database on both sides of the decimal. Scale limits the number of the digits to the right of the decimal. Decimal marker determines what delimiter is used in a number and has three options: decimal point, comma, orspace. The Prefix and Suffix settings determine what goes before or after the field,respectively; these are places where you might put monetary symbols (prefix) or units ofvelocity (suffix).

Node Reference is very specialized, and its use depends on what you have defined onyour site. One of the Node Reference widgets limits the links to specific content types.The Views module helps you to create lists and content displays, giving you a non- content type–specific group of nodes that can be referenced. We’ll talk much more aboutthis operation in Part II of this book.

Text is the most general field type, and has the fewest options for widgets. Plain text is run through an internal filter that does not allow any code of any type or specialcharacters (non-alphanumeric characters). This limit helps to ensure that your contentremains safe from hacking. Filtered text allows the user to select a particular filter thatwill be processed when the node is displayed. The available filters are Basic or FullHTML, which allows the field to contain HTML code. The Body field on the defaultStory module with its input format selector below the text area is an example of filteredtext. The Maximum setting gives a cutoff for how many characters can be included inthe Text field. You might use it in a description or a customized teaser for a longer article.

47B

Exercise 3-2Changing the Widget Type

It turns out that the Text field multi-select list widget wasn’t quite what Joe’s Shirtsneeded. Check boxes might make it easier for a user to see all of the shirt sizes available.Let’s make widget a check box and observe the changes.

1. Navigate to Administer >> Content management >> Content types >> Joe’sShirts >> Manage fields >> T-shirt size >> Configure.

2. Click the button labeled “Change basic information.” It will return you to thescreen where you chose your widget type.

3. Change the widget type to check boxes/radio buttons and continue.

4. No further changes are needed, so save the field settings.

When you try to create a new shirt (Create content >> Joe’s Shirts), observe the change(see Figure 3-5). The multi-select text box has been replaced with check boxes. This for-mat will make it easier for Joe’s employees to see all of the available sizes and will helpthem avoid making multi-click mistakes. It also will let them uncheck particular sizeseasily if they run out of a size. If you haven’t created any shirts, take some time to do soand see how the added field works.

Figure 3-5 Check boxes instead of a multi-select list

Constraining Data with Widgets

Date ModuleThe Date module is one of the single most useful add-ons to the core of CCK. Date is aDrupal module that is designed to use CCK’s structure, forms, and user interface (UI) toadd dates to content types. While not in the core feature set of CCK, the Date module isone of the most useful additions you can make to your toolset.

Date brings an entire set of new features to the party, enabling you to set up speciallyformatted fields for different date functions. Drupal provides a timestamp within its core;this module takes dates and modifies them to fill your own needs.

Install the Date ModuleAt this time, we’re going to look at what Date does with CCK, namely how it adds new fieldtypes and what options it makes available to you.

Date can be downloaded from http://drupal.org/projects/date. Take a few minutes todownload, install, and enable the module.

Date creates three new field types: Date, Datestamp, and Datetime. Datestamp is theUNIX timestamp, which is very useful for programming, database work, and some levelsof sorting, but is not very user friendly. Realistically, users should not see the raw internalvalues of the database. Datestamp also has the disadvantage of only allowing for datesback to January 1, 1970. The Date field type is a basic string, stored as text. This is veryuser readable, but it cannot be used for anything except display. The Datetime field typeprovides a database-native timestamp that can be used for most dates needed by users. Itcan be sorted, easily queried for, and used in calculations. This type provides all the samebenefits as Datestamp, but has greater flexibility in actual calendar date usage. We recom-mend using Datetime over the other date field types for its increased flexibility as well asits better performance for indexing.

Date also introduces some new widget types: a Text field with custom input format, aText field with jQuery pop-up calendar, and the familiar select list. The jQuery calendarprovides a simple clickable interface that makes it very easy to pick a date, while the cus-tom input format is a drop-down menu in the field settings that gives you over a dozenways to set the date display.

Settings for the particular data type start with a default value, which is amenable tofurther customization depending on the option you choose. You can leave the fieldblank, default to the time when you’re creating the content, or choose a relative date. Ifyou choose a relative date, you must open and use the Customize Default Value collapsedfieldset, shown in Figure 3-6. To make the best use of the relative date, you’ll need tohave an understanding of PHP. The fieldset contains a link to the appropriate PHP reference page. A relative time value uses the PHP strtotime function. Check the PHPdocumentation for a full explanation of its usage.

You can create a custom input format for your date display. The regular drop-downmenu for input format lets you choose which way the year, month, day, and exact time

48B Chapter 3 Deeper into Fields

49BDate Module

Figure 3-6 Customize the default value

should be displayed under normal circumstances. If a custom format is provided, it willoverride the default date display for that field in that content type.

One of the things Date can do is provide choices for how far forward or back youryear selection list should go, if you use the select list widget. It defaults to three years ineither direction. Time increments can be adjusted for the minute and second fields ifthey are visible.

One of the most noticeable differences between the Date and CCK settings for theoriginal field types is the field label formatter. “Customize date parts” shows the optionsfor placement of the labels of year, month, day, and so forth. We’ll be able to change thelook of it when we talk about themes later in this book. However, like the base CCKfields, it still contains the same text box to provide user-facing help text.

The Date module has its own complete group of global settings that are specific to itsuse, as well as the basic “Required” and “Number of values” settings that all CCK-basedfields have. Global settings start off with a “To date,” which may be optional, required, ornever used at all. It is useful for things such as news articles about events that run for acertain length of time. Next is “Granularity”; these check boxes break down the time inyear, month, day, hour, minute, and second increments. Unchecked boxes are not dis-played on the content creation page.

Finally, the “Date display” shows the format in which your users will see the date onyour content pages. It also can accommodate a custom format, which uses PHP’s dateformat string. The collapsible fieldset for “Additional Display Settings” gives furtheroptions for showing dates, such as long, medium, and short—all of which have theoption to show a custom format.

The last field is “Time zone handling.” It determines which time zone the user view-ing content will see. You may want to standardize your site to your local time zone,UTC, or always show the user his or her own time zone.

3. Save the new field.

4. Change the default value to “Now” for this content type. No customization isnecessary right now—we’ll assume the batch information is being entered on theday it is made. Input format is fine the way it is, and we don’t have a need tochange the “Years back and forward” or the “Time increment.”

If you’re doing something like converting a handwritten notebook of recipesinto a database, you might change the “Years back and forward” selection. If youhave 15 years worth of entries with dates, changing the “Years back” adds 15 yearsinto the calendar drop-down menu.

5. Customize the date parts. Having the labels above the date seems reasonable fornow.

6. Skip down to the global settings and enter the following values:

Exercise 3-3Using the Date Field

To keep track of our batches for our homebrewing example, we will use a date for eachbatch brewed. We’ll want to have an easy reference back to the original recipe used, evenif we made modifications for a particular batch.

1. Go to the content type page (Administer >> Content management >> Contenttypes), and select “Manage fields” next to the Batch brewed content type.

2. Add a new field using these values:

50B Chapter 3 Deeper into Fields

Field Value

Label Brewing date

Name brewing_date

Field type Datetime

Form element Select list

Field Value

Required Checked

Number of values 1

To date Never

Granularity Year, Month, Day

Default display Medium

Time zone handling No time zone conversion

7. Save field settings.

51BComputed Fields

Figure 3-7 The Brewing date field on the Batch brewed creation page

Computed FieldsComputed Field (http://drupal.org/project/computed_field) is another add-on modulewith a basis in CCK. Unlike many CCK modules, however, it requires some knowledgeof PHP to be useful. This module can create a value from other values and return thatvalue to you. You can choose to store this value in the database, decide whether to dis-play it, and do some level of formatting. Because the computed value is calculated byPHP, this field is able to access anything that Drupal itself can access.

The new data type and widget for this field are easily spotted, as both of them alsohave the name Computed. Computed data fields allow use of only the computedwidget, so there is no room for confusion in what to choose.

The most critical field form data is the Computed Code field. This Text field containsPHP that will calculate a value based on other values. A limited number of variables areavailable for use: $node, $field, and $node_field. This is definitely an area where anunderstanding of PHP and Drupal internals becomes useful. If you don’t have eithertype of knowledge, that’s still okay! Just follow along: Our hope is that the discussionhere will give you an idea of how the Computed Field module works and a base forwhere you’ll take your own data.

The next pair of settings deals with the field display. Selection of a check boxdetermines whether the computed field will appear in the node when it is displayedto the end user. In addition, a Text field uses PHP to determine how the field willbe displayed. It uses the PHP $display variable, which needs to have a valueassigned to it.

The remaining fields are a group that determine whether and how your data willenter the database. If you decide to save the data, it is calculated and stored when thenode is saved. Selection of a check box determines whether the data will be stored.If the box is checked, then you must choose which SQL format the data will bestored in: int, float, varchar, text, or longtext. This is a group of radio but-tons, so you must choose one. Data length is a field that is also required for storagepurposes; you may set a default value for this field. The “Not NULL” check box flagsthe field for display only if it has a value, and the final check box flags the field forsorting.

3. Save the group. You do not need to make any changes on the configurationscreen.

4. Create a new field for original gravity with these values:

Exercise 3-4 Creating a Computed Value

One thing all brewers want to know is how strong a batch is. The strength of beer,which is known as alcohol by weight (ABW), varies depending on many factors duringthe brewing process. A formula is used to determine that strength based on the originaland final specific gravities of the fluid: alcohol by weight = 76.08(original gravity – finalgravity)/(1.775 – original gravity). We want to keep these together, so let’s use a field-group. Let’s add this formula to our homebrewing example.

1. Open the Batch brewed content type (Administer >> Content management >>Content types >> Batch brewed).

2. Create a new group using “Add group” and these values:

52B Chapter 3 Deeper into Fields

Field Value

Label Alcohol levelGroup name alcohol_level

Field Value

Label Original Gravity

Field name original_gravity

Field type Float

Widget Text field

5. Create a second field for final gravity with the same settings used for original gravity.

6. Create a third field for the computed value with the following settings:

Field Value

Label ABW

Name alcohol_by_weight

Field type Computed

Widget Computed

53B

Field Value

Name alcohol_by_volume

Label ABV

Field type Computed

Widget Computed

$og = $node->field_original_gravity[0]['value'];

$fg = $node->field_final_gravity[0]['value'];

$node_field[0]['value'] = 76.08 * ($og - $fg) / (1.775 - $og);

This code sets a pair of new variables ($og and $fg), sets their values to the valuea user inputs on the form, and uses a third variable ($node_field) to calculate afinal value that will be returned.

8. Make sure “Display this field” is checked; it should be by default.

9. For the database storage settings, use the Float data type, with a data length of 5.This is a longer value than will ever be needed.

Now we have a place to enter original and final gravity values for our batch. When abatch is entered and saved, the computed field will calculate the percentage and display iton the page.

If you wanted to take matters a step further, this field could be used to calculate alco-hol by volume (ABV). ABW is generally used for beer, while ABV is used for wines. Todo that, you would need another field.

1. Create a new field for Batch brewed using these values:

7. In the global settings for the Computed Code field, include the following snippetof code:

2. Use the following for the computed code:

$abw = $node->field_alcohol_by_weight[0]['value'];

$fg = $node->field_final_gravity[0]['value'];

$node_field[0]['value'] = $abw * ($fg / 0.794);

3. Use the same settings for the other fields as you used in the ABW field, and savethe changes.

ABV will appear as another value in your batch. When you created the fields, noneof them were marked as required. You won’t know the final gravity until the batch isdone, and it’s always best to enter batch information while it’s fresh. Another thing tobe aware of: Because ABV is using ABW for its calculation, ABW must be calculatedfirst. If your fields are out of order, your values will be incorrect. Order matters!

Computed Fields

54B Chapter 3 Deeper into Fields

Now all of the fields are grouped together and can be positioned with one grab of thehandle next to the fieldgroup name, as shown in Figure 3-8. Notice how the fieldswithin the group are indented, making it easy to tell which fields belong to that group.

The Computed Field module can cause a great deal of frustration for those withoutPHP development experience. However, even a little knowledge can turn this field intoone that your site simply cannot function without.

Link and Email FieldsLink and Email are two additional contributed modules that add new fields to yourCCK user interface. Link is found at http://drupal.org/project/link; Email is available athttp://drupal.org/project/email. The fields added by these modules have similar func-tions, but slightly different uses. Both modules provide a field that allows the node tohave a specific place to add HTTP or email links. In some cases, you may provide theselinks in the body of the node. Using the field types has several advantages, however. Thefield type will be easily usable by Views; like other fields, it can be themed separately soit is more obvious to the page viewer; and it can have its own label.

The Link module has a number of potential uses. For example, you might create anode that contains a blog roll or a wish list. You could use it for news articles to createlinks back to the original photo or other source material. The Link module also pro-vides the nofollow option, which helps prevent some search engines from followingthe provided link. Link has a somewhat unusual feature in its global settings in that ithas the ability to add the link to CSS classes, feeding it automatically to some styles.

Figure 3-8 The Alcohol level fieldgroup

4. Look at the list of fields. Use the cross (grab handle) to move all of the fields wejust created into the “Alcohol Level” group.

5. Save the changes.

55BHighly Visual Media

Email fields are among the simplest fields in functionality and configuration terms.The Email module creates only one new field type and uses only one widget, a plainText field. When used, this CCK add-on allows an address to be input that creates amailto: link in the node. It will check to ensure that the email address has a valid for-mat. With the Invisimail module, it can also have the email address encrypted, therebypreventing spam bots from harvesting addresses from your site.

Highly Visual MediaOne of the major uses of content in Web site development today is to provide highlyvisual media. Pictures, streaming audio, and video are big business and vitally importantto many corporate Web sites. For example, clothing stores want pictures of their items tobe available to potential customers, musicians want tour photographs and album coversto be visible, and so on. Again, add-ons to CCK add to the power of Drupal and enabledesigners to meet these challenges.

The various Image modules (e.g., ImageField, ImageCache, ImageAPI) provide thefirst step toward meeting these needs. Unlike the field types previously discussed, theImage modules are a group, and they require another field add-on module: FileField. Asa group, these modules provide a way to feed images to a specific content type, or tofeed to other modules via the API.

FileFieldFileField (http://drupal.org/project/filefield) performs a function that some users may ques-tion: its purpose is to upload files. An optional module is included with the Drupal corecalled Upload, whose purpose is to upload and attach files. So why is FileField needed?

First, file fields as CCK fields are more flexible than the core’s functionality. Core uploadis limited by the size of the file that can be uploaded, and only a certain group of file typescan be uploaded at all. Files uploaded using core upload are listed as file attachments. Thatterminology is not very clear when you have a specific need for a particular type of file, orif you want to provide text to help users decide what they should be uploading.

The FileField module is very similar to the other CCK extensions. It creates a Filefield type and adds new widgets for its own use: File Upload, Extensible File, and Image.This module allows you to attach a file that can be text, an image, or some other type offile and to make this file available to others viewing a particular node. In theory, youcould simply use FileField to upload images, but the Image modules give you signifi-cantly more control over the files and the ability to manipulate pictures to some degreeas they are being uploaded to your site.

FileField has a few content type-specific settings that are specialized for its use as wellas global settings that restrict viewing of uploaded files. For each content type, you mayspecify the file extensions (e.g., .jpg, .txt, .doc) that are valid for uploading to a node.You may also limit the upload size for each file as well as the total upload size for all ofthe files. For example, you might specify a 5-megabyte limit per node, which means that

56B Chapter 3 Deeper into Fields

a user could upload five 1-megabyte files or one 5-megabyte file. If you use this function-ality to upload an image using the Image widget, you also have the option to limit theresolution of the file being uploaded.

Globally, the field type requires to two values to be set: “Default list value” and “Howshould the list be handled.” The default list value option determines whether the files arehidden from view when they are attached. The list handling question determines if theuser attaching the file can change the visible or hidden setting versus the default beingstrictly enforced by the module so that users cannot change it.

ImageFieldImageField (http://drupal.org/project/imagefield) starts with the same base as FileField.This again begs the question of why you would use ImageField instead of image. Thedifference is, again, the advantages of CCK fields for creating data within a node versususing a separate module to create an entire node.

When you create the field, the field type Image is available, with Image as the singleavailable widget. The settings page, however, looks exactly like the Image widget forFileField, with the same settings and instructions. ImageField’s permitted extensions forupload are prepopulated with image-based extensions (e.g., .jpg, .jpeg, .png, .gif)rather than the default .txt extension provided by FileField, but otherwise they are thesame. It is recommended that the ImageField module and widget be used over FileField’smodule and widget, however. ImageField is set up specifically to deal with images, anddoes not have to make allowances for other types of files.

Once you have created a field, you can go to the content type. There, a field with abrowse button will be available when you create a new node. When an image isuploaded, it appears in a list format on the node. This means the picture is not embedded into the page, but rather a link with the image’s filename is provided.

ImageAPI, ImageCache, and ImageCache UIImageAPI, ImageCache, and ImageCache UI form a set of helper modules. CCK obtainsa link from ImageCache to provide formatters for ImageField, if ImageField is present.

ImageAPI is a module that is not visible to the general user. It performs basic imagemanipulation for other modules such as ImageCache such as resizing, rotation, and crop-ping so that images can fit into the required space provided by the content type adminis-trator. Note that this module does not actually save images—that task is left to othermodules.

ImageCache works in conjunction with the ImageAPI to create a namespace inwhich the image is stored. Using this module, you can set up a group of default actions(presets) to be performed on an image, which in turn can be used by other modules toalways perform those presets when an image is uploaded. ImageCache also defines atheme function so that your template file can easily add a modified image to any nodeof that particular type. The module includes a UI to make tasks easily visible in theadministrator’s interface.

SummaryThere are many ways you can use a field to create the site you’re seeking. Understandingand using fields and helper modules for those fields creates possibilities for including anykind of data on a Web site. Knowing the core of CCK’s provided data types and widgetslets you examine how well those functionalities can fit the needs of what you need tocreate. With the addition of the various modules that contribute to the extension ofCCK, you can go farther, faster.

57BSummary

This page intentionally left blank

Index

Aabstraction, in object-oriented

programming, 186B

ABV (alcohol by volume), 53B–54B

ABW (alcohol by weight), 53B–54B

access, Views UI

access log view in Views Add Creationpage, 115B

plugins, 193Brestrictions, 120B

access rules, Panels UI

adding access controls, 245B–246Boverriding core display pages, 247Boverview of, 244B–245Bselection rules as form of, 230B

Acquia Drupal stack, 11B

Add content

access controls, 245Barguments in panes, 265Barguments in panes with views, 269Bcontent panes, 238B–242Bcontexts, 259B, 261Bin Flexible panel layouts, 278Bnode in Node Reference field as

context, 272Bnode override page, 249–250Bnode views, 248Brelationships, 272Bstyles to panel regions and panes, 283Btaxonomy overrides, 252B

taxonomy terms, 263B–264B

views in panes, 266B–268B

Add Content Type page

adding new types with, 17B–18B

creating field with complex settings, 30B

creating new content type, 13B

Add display button

adding page display to arguments, 143B–144B

creating block display, 131B

creating page display, 134B

using view pane display with argument, 270B

Views UI, 117B

Add pages, Views, 112B

Add Variant option, Panels UI

defined, 230B

node override, 249B

taxonomy override, 252B

add_field( ), query object, 198B

add_groupby( ), query object, 199B

add_having( ), query object, 198B

add_orderby( ), query object, 199B

add_relationship( ), query object,197B

add_table( ), query object, 197B–198B

add_where( ), query object, 198B

Additional Display Settings, Date module, 49B–50B

add-on field modules, 14B

add-on helper modules, 14B

adjust_join( ), query object, 197B

Admin title, pane settings in Views, 268B

administrators

dashboard, 308B

menu links for Panels, 225B

Advanced Help

Calendar, 308Boverview of, 110Breading as documentation for module

you are reporting, 310BViews, 208B

Advanced Profile Kit (APK), 308B

AJAX, Basic settings in Views UI, 120B

alcohol by volume (ABV), 53B–54B

alcohol by weight (ABW), 53B–54B

aliases

execution-related hooks and, 205Bfor query object, 198B–199Breferring to given nodes, 5Busing in URL to go to page

containing view, 133BAllow settings, Pane settings, 268B, 271B

Allowed Block content, Panel settings, 227B

Allowed values setting, fields, 29B, 31B, 33B

Analyze button, View left-side tabs, 117B

anonymous page caching, 182B

ApacheSolr module, 306B

APIs (application programming interfaces)

CCK. See CCK APIdeveloping CCK with consistent, 8Bflexibility of node, 4BViews. SeeViews API

APK (Advanced Profile Kit), 308B

architecture

data, 185BDrupal core procedural, 186B–188BPanels pluggable, 221BViews using object-oriented, 185B

arg( ) function, 144B–145B

argument default plugins, Views, 193B, 212B

Argument input, Pane settings, 268B

argument validator plugins, Views, 193B,212B

328B Add content

arguments

adding, 141B–142Bconfiguring, 139B–141Bexpanding and stacking, 144B–145Bas filters, 138B–139Bhandlers for, 316Bintroducing with Views, 264B–265Bnot passing to blocks, 144B–145Boverview of, 137Bas part of view, 142B–143Busing feeds with, 143B–144Bin view execution cycle, 201B–203BView UI settings for, 122B

arguments in panes

Add content modal for views,266B–267B

adding view, 265B–266Boverview of, 264B–265Busing view pane display with,

270B–271Busing with view, 269B–270Bview pane displays, 268B–269B

Arguments text box, Pane settings, 269B

ascending sort order, 106B

attached views, 306B

attachment display

defined, 116Bdisplay-specific settings for, 122Boverview of, 135Buser feeds with arguments, 144Bworkflow settings, 21B

.attachment-after class, 155B

.attachment-before class, 155B

attributes, node, 6B–7B

Authoring information

adding new nodes, 235B–236Bchanging using Views Bulk

Information, 307B

as node content, 6B

overriding core node editing pages, 253B

query displaying, 107B

using relationship for node,271B–272B

autocomplete widget, 45B–46B

Bbackup, site, 292B

base tables

concept of, 183B

declaring tables inhook_views_data( ) as,208B–209B

overview of, 191B

relating tables to each other,206B–207B

and relationships, 191B–192B

base theme, preserving, 60B–61B

Basic page, Display fields, 34B–35B

Basic settings, Panels UI, 230B

Basic settings, Views UI

creating page display, 134B

determining themes views are using, 156B–157B

overview of, 118B–121B

user feeds with arguments, 144B

Basic tab, Views UI, 126B–127B

block displays

creating, 131B

creating blocks with, 132B–133B

defined, 116B

display-specific settings for, 121B

mini-pagers suited for, 120B

blocks

not passing arguments to, 144B–145B

overview of, 132B–133B

329Bblocks

pushing into page template, 218Bworking with, 133B

blogs

Blog entry content type, 5Bblog_rss view, 309Btaxonomy used in, 262B

body field, of nodes, 7B, 20B

Book outline settings, panel nodes, 235B

Book page content type, 5B, 36B

book parents, 272B

breadcrumb trail

arguments modifying, 202Bchanging in Panels dashboard, 226Bediting mini-panel using, 237Bexecuting views display, 203B–204Bhow it works, 30BNode Reference tool and, 42Bwildcards and, 140B

bugs, reporting issues, 312B

build( ) method, view execution cycle, 202B–203B

Bulk Export module, CTSuite, 222B

Bulk export page, Views UI, 127B

Ccaching

Clear Views’ Cache button, 126Bclearing if field settings change, 98Bcreating data for fields, 95BCSS, 285Bdisabling pluggable, 126Bdisabling Views, 126Bfor each view display, 120Bhooks to improve performance,

201Bpanels, 221B, 242Bquery optimization with, 181–182Bsaving views, 142B

Calendar module, 307B–308B

Canvas menu, Flexible panel layout, 277B

Cascading Style Sheets. See CSS (Cascading Style Sheets)

Category, Pane settings in Views, 268B

CCK (Content Construction Kit) module

adding fields with, 7B

Calendar module, 307B–308B

creating new content type, 11B–15B

defined, 1B

development of, 8B–10B

Drupal version numbers and, 10B

exporting, 295B–296B

forum on status of, 9B

getting started with, 10B–11B

CCK API

creating data for fields, 95B–97B

creating field instances using ContentCopy, 91B

creating field instances using CRUDAPI, 91B–95B

field model. See field model

formatter modules, 87B–91B

helper functions, 97B–98B

using, 75B–76B

widget type modules, 85B–87B

/cck/theme directory, 59B–60B

Center region, Flexible panel layout, 277B

Chaffer, Jonathan (JonBob), 9B

Chaos Tool Suite. See CTools (Chaos ToolSuite) module

check boxes/radio button widget, 45B–46B

check_markup( ) function, Contemplate, 72B–73B

check_plain( ), Contemplate module, 72B–73B

check_plain( ), dsm( ) function, 167B

330B blocks

Choose Layout option

node override, 249Btaxonomy override, 252B

classes

in Panels-based CSS, 286B, 289Bin Views, 153B–156B, 163B–164B,

318B–326BClear Views’ Cache button, 126B

Clone option, Panels UI, 229B, 260B

cloning views, 112B, 132B

code flows, handlers, 210B

Column menu, Flexible panel layout, 277B

columns, table style of view, 114B

comments

for content types page, 22B–23Bfor node contexts, 261Bfor node overrides, 250Bfor node view page override,

248B–249Bfor panel nodes, 235Btemplate for, 164Bview, 115B

Computed Code field, 51B

Computed Field module, 51B–54B

construct( ) method, 195B, 201B

constructors, object-oriented programming, 190B

Contemplate (Content Templates) module,themes, 71B–73B

content

adding to panels, 237B–242Bchanging layouts and, 279B–280Bconfiguring development environ-

ment, 291Bnode override, 249B–250Btagging to build taxonomy, 262Btaxonomy override, 252B

Content Construction Kit. See CCK (ContentConstruction Kit) module

Content Copy module, 14B, 91B

Content module, 14B

content panes

adding, 238B–242B

configuring existing, 243B–244B

enabling views on Panel dashboard as, 226B–227B

introducing arguments with, 265B

Content Permissions module, 14B

Content Profile module, 272B

Content setting, Variants tab of Panel UI, 231B

Content Templates (Contemplate) module,themes, 71B–73B

content types

adding fields to, 24B–29B

advantages of CCK, 9B–10B

creating fields for existing, 27B–29B

creating new, 11B–15B

creating new, with Flexinode, 8B–9B

default, 4B–5B

Drupal basic, 4B

limiting links to specific, 46B

sharing fields between, 29B

what to know before creating, 17B

content types page

Comment settings, 22B–23B

creating new content type, 11B–12B

Export tab, 22B

Fields tab, 22B

Identification settings, 18B–19B

Import tab, 22B

overview of, 17B–18B

Submission form settings, 19B–21B

Workflow settings, 21B–22B

$content variable, 68B

content_clear_type_cache( ), 98B

content_database_info( ), 97B

331Bcontent_database_info( )

content_field_instance_create( ), 91B–92B

content_field_instance_read( ), 94B

content_field_instance_update( ), 94B

_content_field_invoke( ), 77B

content_fields( ), 97B

content_format( ), 97B

content_write_record( ), 98B

content.crud.inc, 92B

contexts

adding, 260B–262Bcreating in panels, 221Bdesigning page content/layouts

with, 280Boverview of, 257B–258Bin Panel pages, 258B–259Btaxonomy in, 262B–264Btaxonomy override, 251B–252BUser Reference and Node

Reference, 272B–273BContexts setting, Variants tab of Panel UI,

230B

Convert tab, Views UI, 127B–128B

copying template files, 156B

COUNT function, query object, 198B–199B

CPU time, development time vs., 177B

Create new revision option, Workflow,21B–22B

Create Panel screen, panel nodes,234B–235B

Create Variant

node override, 249Btaxonomy override, 252B

CRUD (Create, Read, Update, Delete) API, forfield instances, 91B–95B

CSS (Cascading Style Sheets)

caching, 285Bcreating new panel style, 282B–283B

grouping fields in template, 172B–173Bidentifying particular pane for styling,

286B–289Bin Panels UI, 284B–285Bsetting properties within panels using

Stylizer, 280Bin source code, 285B–289Btheming a fieldgroup, 66B–68B

CTools (Chaos Tool Suite) module

contexts. See contextsdownloading, 222Bhistory of, 218Bmanaging access rules with Page

Manager, 244B–246Boverview of, 223B

Custom content panes, CTSuite, 222B

custom pages, 228B

Custom rulesets, CTSuite, 222B

Customize date parts, Date module, 49B

Customize Default Value, relative dates, 48B–49B

Ddata

creating for CCK fields, 95B–97BViews API architecture, 185B

data types

CCK, 26B–27Bchoosing field for, 39B–43Bconverting in development

site, 294Bfor field in Type fields, 25Brelational database fields, 103Bwidgets for, 44B–47B

database columns operation,hook_field_settings( ), 80B–81B

database schema

declaring fields on tables, 209B–210B

332B content_field_instance_create( )

declaring tables inhook_views_data( ), 207B–209B

overview of, 206Brelating tables to each other,

206B–207Bdatabase storage, 8B–9B

Date module

Date field, 50B–51Bdefined, 14Boverview of, 48B–49Brequired by Calendar, 308B

Datestamp field type, 48B

Datetime field type, 48B

db_query( ), query object, 198B–199B

db_rewrite_sql( ), view executioncycle, 203B

Decimal field type

defined, 26B, 46Bworking with, 40B

Decimal marker setting, widget types, 46B

default content types, 4B–5B

default display

creating view, 128B–130BDate setting, 49B–50Bdefault template vs., 158Bin Views UI, 115B–117B

default options, Workflow, 21B

default templates, 156B–159B

default views

enabling and changing, 113B–114Bview execution cycle checking

for, 201BView settings, 117B–118B

$definition array, views_object, 194B

Delete operations

content type List page, 18Bhook_field( ), 82BPanels UI, 229B

Deploy module, for site migration, 299B

deployment. See site deployment

descending sort order, 106B

DESCRIBE statement, vs. EXPLAIN inMySQL, 180B–182B

Description field, Identification setting,18B–19B

design, Web site, 14B–15B

destroy( ) method

view execution cycle, 203Bviews_object, 195B

destructors, object-oriented programming, 190B

Devel module, installing Theme Developerwith, 70B–71B

development environment, configuring,291B–293B

development time, CPU time vs., 177B

directories

installing modules into, 11Bthemes, 59B–60Bviews, 156B

Disable option, Panels UI, 230B

display

modules in Panels, 222Boverriding. See overriding core display

pagesPanel content screen settings, 238Bpoint-and-click layout in Panels, 219Btemplates, 159B–160B

Display Fields tab

adding fields, 24B–25Badjusting display, 34B–35Bexcluding fields, 68B

display plugins, Views API

defined, 192B, 212Binstantiating in initialization, 201Blist of, 317B

$display variable, PHP, Computed Code field, 51B

333B$display variable, PHP, Computed Code field

displays, Views UI

adding views to panel pane with,268B–269B

Basic settings, 118B–121B

block displays, 131B–133B

defined, 115B

executing, 203B–204B

page displays, 133B–135B

of specific settings, 121B–122B

types of, 116B–117B

using attachments, 135B

using feeds, 135B

using left-side tabs to add, 115B–116B

View settings, 117B–118B

viewing on Views list page, 111B

DISTINCT statement

query object, 197B–199B

removing duplicated records fromview, 120B

documentation

from development to production, 294B

reading for module you are reporting, 310B–311B

drag and drop, of existing content panes, 244B

Drupal

development of CCK, 8B–9B

installing for CCK, 10B–11B

layouts, 218B

“learning cliff ” of, 102B

version numbers, 10B

drupal_execute( ), 95B–96B

drupal_render( ), 88B

drupal_set_message( ), 167B

drupal_write_ record( ), 98B

Drush module, for site migration, 299B

dsm( ) function, 165B, 167B

EEdit operation, content type List page, 18B

editing

enabling and changing default view,113B–114B

of existing view in Add page, 112Bmini-panels, 237Boverriding core node editing pages,

253B–255Bpanel content, 238Bpanel nodes, 236B

Email module, 55B

embedding queries, 179B–180B

empty text, 121B

encapsulation, 186B, 189B

ensure_table( ), query object,197B–198B

Exclude option, Display Fields tab, 68B

execute( ), view execution cycle, 203B

execute_display( ), Views, 203B

Existing field, field display, 34B

expanding arguments, 144B–145B

EXPLAIN statement, query optimization, 180B–182B

explicit relationships

overview of, 192Brelating tables to each other as,

206B–207BExport option, Panels UI, 229B

Export tab, content types page, 22B

exporting structures

CCK, 295B–296BPanels, 298B–299Bsite deployment and, 294B–295BViews, 296B–297B

exporting views, 112B, 305B

exposed filters, 145B–147B, 163B

Extra column, EXPLAIN statement, 181B

334B displays, Views UI

Ffeature requests, 312B

Features module, site migration with, 299B

feed display

adding to arguments, 144Bdefined, 116Bdisplay-specific settings for, 121Boverview of, 135B

.feed-icon class, 155B

feeds, using with arguments, 143B–144B

field handlers, Views API, 315B–316B

field IDs, field names vs., 158B

field instances

creating using Content Copy module,91B

creating using CRUD API, 91B–95Bdefined, 17B, 37Boverview of, 38B

field model

for custom field types, widget types orformatters, 77B–79B

field type modules, 79Bhook_field functions, 80B–84Bfor new field types, widget types and

formatters, 76B–77Boverview of, 76B

field modules, 13B–14B

field names, vs. field IDs, 158B

field templates

changing parts of themes, 64B–65Bcreating themes, 61Bfiles and filenames for, 63Bvariables available in, 63B–64B

field type modules

hook_content_generate(), 84Bhook_content_is_empty(), 84Bhook_field( ), 82B–83B

hook_field_info(), 79B–80B

hook_field_settings( ), 80B–82B

field types

creating custom, 77B–79B

creating field instances using, 91B

creating new, 76B–77B

defined, 17B

modules defining, 79B

field_name, creating field instances, 91B

$FIELD_NAME, node templates, 65B–66B

Fieldgroup module, 14B

fieldgroups, themes for, 66B–68B

fields

adding complex settings, 30B–33B

adding to content types, 24B–26B

adding to content types with CCK,13B–15B

adding to content types withFlexinode, 8B–9B

adding to existing content types,27B–29B

adding to nodes, 7B

building SQL queries in Views using,107B–108B

CCK fields composed of, 76B

changing display of, 33B–36B

choosing types, 39B–43B

Computed Field module, 51B–54B

concepts, 17B

for content type pages. See contenttypes page

creating data for CCK, 95B–97B

data types, 26B–27B

Date module, 48B–51B

declaring table, 209B–210B

defined, 17B

exporting CCK, 296B

335Bfields

filtering and sorting, 105B–106B

identifying insecure, 72B

Link and Email, 54B–55B

migration of existing settings not supported for, 294B

overriding core node editing pages,253B

for panel nodes, 235B

retrieving settings, 97B

row style template file, 161B–162B

rows made up of, 103B

sharing, 36B–38B

for simple view, 129B–130B

template, 167B–174B

using widgets, 29B, 43B–47B

View UI settings for, 122B

visual media, 55B–56B

what to know before creating, 17B

Fields tab, content types page, 22B

File attachments, panel nodes, 235B

File field type, 56B

File views, 115B

FileField module, 55B–56B

files, adding to themes, 68B

filter handlers, Views API, 316B

filtered text, 40B, 46B

filters

arguments used as, 138B

building SQL queries in Views, 107B

creating simple view, 130B

for criteria in Views list page, 110B–111B

exposed, 145B–147B

relational database, 105B–106B

sorting panel page, 228B

Views UI, 123B–124B

Flag module, 305B

Flexible layouts, 275B–278B

Flexinode module, 8B–9B

Float field type

available widget types, 46B

defined, 26B

working with, 40B

Force single setting, exposed filters,146B–147B

foreign keys, 104B–105B

form operation, hook_field_settings( ), 80B

formatter modules, 87B–91B

formatter_info( ), 88B–89B

formatters

CCK fields composed of, 76B

changing how field is displayed, 24B

creating field instances, 91B

creating new, 76B–77B

creating themes, 61B

customizing, 77B–79B

formatting content, 97B

Forum topic content type, 5B

forums

getting help with Drupal, 311B

on status of CCK, 9B

Full node menu, Display fields, 35B

full node view, 6B

Full pager setting, Views UI, 120B, 135B

functions, theme, 59B

GGarland, 59B–61B

General setting, Variants tab of Panel UI,230B

Getting Started page, Views list, 110B

global null variable, arguments, 137B

336B fields

337Bhook_widget_settings( )

global settings

Computed Code field, 53BDate module, 49B–50Bfields across all node types, 43B–45B

grab handles, moving field into content type, 25B–26B

Granularity setting, Date, 49B–50B

grid style, views, 114B, 160B

GROUP BY clause, query object, 199B

grouping in template

grouping fields, 170B–174Boverview of, 169B–170Bsecond method for, 174B–175B

groups

adding relationships in View, 122Bchanging field display in, 33B–34Bcreating computed value, 52Bcreating with User Reference,

42B–43Bfield management, 25B

guidelines, module, 309B–310B

Hhandbooks

reading Drupal documentation in,311B

writing pages for, 314Bhandlers

naming conventions, 193B–194Bplugins vs., 210B–212Bproperties and methods for query

object, 195B–199Bproperties and methods forviews_object, 194B–195B

utilized in Views, 193B, 315B–317BViews classes for, 318B–324B

headers, adding to views, 120B–121B

helper functions, for custom programming, 97B–99B

helper modules

add-on, 14Bdefined, 13BPanels, 222Bfor site deployment, 299Bfor themes, 69B–73Btypes of, 14B

Hidden option, Display Fields tab, 68B

hook_content_build_modes( ), 98B

hook_content_generate(), 84B

hook_content_is_empty(), 84B

hook_content_notify( ), 78B

hook_field( ), 82B–83B

hook_field_info(), 79B–80B

hook_field_settings( ), 80B–82B

hook_form validation and submission hooks, 95B

hook_form_alter( ), 77B

hook_formatter_info( ), 88B–89B

hook_theme( ), 90B–91B

hook_views_admin_links_alterhook, 205B

hook_views_data( ) method,206B–209B

hook_views_handlers,views_object, 194B

hook_views_plugins, views_object, 194B

hook_views_pre_build hook, 202B–203B, 205B

hook_views_pre_executehook, 203B, 205B

hook_views_pre_renderhook, 203B, 205B

hook_views_pre_view hook, 205B

hook_views_query_alter hook, 205B

hook_widget( ), 87B

hook_widget_info( ), 85B–86B

hook_widget_settings( ), 86B–87B

338B hooks

hooks

CCK’s API using, 75Bcreating custom field types, widget

types or formatters, 77B–78Bdatabase schema and, 206B–210Bdefined, 76Bexecution-related, 204B–205Bfield type module. See field type modulesfinding source of, 76Bformatter module, 88B–91B.install file for modules, 78B–79Boverview of, 200BViews implementing, 200B–201Bwidget type module, 85B–87B

hooks_views_handlers( ), registering handlers, 211B

hooks_views_plugins( ), registering plugins, 212B–213B

HTML files, 156B

Iicons, styling views, 114B

Identification, content types page, 18B–19B

Image field type, Email, 55B

Image modules, 55B–56B

ImageAPI module, 56B

ImageCache module, 56B

ImageCache UI module, 56B

ImageField module, 56B

implicit relationships, 191B, 206B

importing

content types page Import tab, 22BImport/Export tool, 281BPanels UI Import variant option, 230Bvariants for taxonomy override, 251BViews Import module for, 306BViews UI Import page, 125B

indexing

query optimization with, 182B

relational databases, 103B

$info array, CRUD API, 91B–92B

.info file, 61B

informational messages, Flexible layouts, 275B

inheritance, in object-oriented programming, 189B–190B

init( ), view execution cycle, 201B

initialization, view execution cycle, 201B–203B

inner joins, 106B–107B

Input format, node content, 7B

insert operation, hook_field( ), 82B

.install file, 78B–79B

Integer field type

available widget types, 46B

defined, 26B, 40B

IRC, getting help with Drupal, 311B

issue queues, 311B, 314B

Items per page option, Views, 120B

JJavaScript, Basic tab settings for, 127B

JOIN statement

query object, 196Bsharing fields between content

types, 36Bjoins

base tables and relationships, 191B–192B

complex, 208B–209Brelational database, 106B–107B

JonBob (Jonathan Chaffer), 9B

jQuery UI, for Panels in-place editor, 222B

339BMenu settings

Kkeys

registering handlers, 211Brelational database, 103B–105B

LLabel field

changing field display, 33B–34Bcreating field with complex

settings, 31Bfield management, 25B

layout

changing, 279B–280Bnode override, 249Busing Flexible, 275B–278Busing Panels for. See Panelsusing templates for, 156BViews Bonus Pack pre-created

panel, 306Blayout designer, 279B

layout manager, 276B–277B, 279B–280B

Layout setting, Variants tab of Panel UI, 231B

“learning cliff,” Drupal, 102B

left joins, 106B–107B

left-side tabs, Views, 115B–117B

life cycle, bugs, 312B–313B

life cycle, Views, 201B–203B

Limit list to selected items, exposed filters, 146B

Link module, 54B–55B

Link to view, Pane settings in Views, 268B

links

creating reverse, 43Bin full node view, 6Bin new content type, 12Bin title bar on Views list page, 112B

List page

content types, 18BPanel pages, 228BViews, 110B–112B

list style, Views, 114B, 160B

live preview, Views UI

Basic tab settings, 126B–127Bcreating simple view, 130Boverview of, 125Buser feeds with arguments, 144B

load operation, hook_field( ), 81B

local tasks (tabs), full node view, 6B

locked value, field instances with CRUD API, 93B

locks, overriding core display pages, 247B

Mmachine names, 24B

mailto:link option, Email module, 55B

maintenance, and embedded queries, 180B

Manage fields, content type List page, 18B

Manage Fields tab

adding fields, 24B–25Badding form elements to, 98Bchanging field display in, 33B–36Bcreating field for existing content

type, 27B–29BMaximum length, creating field

with, 31B–32B

Maximum setting, widget types, 46B

media, creating highly visible, 55B–56B

Menu module, 4B

Menu settings

Pages, 121Bpanel nodes, 235BPanels UI, 230B

340B methods

methods

object-oriented programming,186B–187B

query object, 194B–195Bviews_object, 194B–195B

Mini panels tab, Panels dashboard, 227B

Minimum number of words field, Submissionforms, 20B–21B

Minimum setting, widget types, 46B

Mini-pager setting, Views UI, 120B

mini-panels

content editing, 238Bcontext editing, 258B–259Bcreating, 220B, 237Bcreating from Panels dashboard, 226Bediting, 237Boverview of, 236B–237BPanels package, 222B

Module name box, Bulk export page, 127B

modules

Advanced Profile Kit for Panels, 308BApacheSolr, 306BCalendar, 308BCCK. See CCK (Content

Construction Kit) moduleComputed Field, 51B–54BCTools. See CTools (Chaos Tool Suite)

moduleDate. See Date moduleEmail, 55Bfield type. See field type modulesFlag, 305Bformatter, 87B–91Bhelper. See helper modulesImage, 55B–56Bimportance of nodes in, 4BLink, 54B–5B5Menu, 4B

Nodequeue, 304B–305BPanels. See Panels modulePathauto, 303B–304Breporting issues about. See reporting

issuesSheetnode, 307BSimpleViews, 307Bthemes directory in, 59BTotal Control Admin Dashboard for

Panels, 308Btypes used primarily in this book,

10B–11BUpload, 4BViews. SeeViews moduleViews Attach, 306BViews Bonus pack, 305B–306BViews Bulk Operations (VBO), 307BViews Datasource, 307BViews Import, 306BViews Slideshow, 305BViews_or, 304Bwidget type, 85B–87B

More link, 120B, 163B

multiple-value formatters, 88B–90B

multi-row text area widget, 45B, 46B

MySQL, as install-ready database, 101B

NName field

changing field display, 33B–34B

field management, 25B

Identification, 18B–19B

naming conventions

field templates, 62B–63B

fields, 79B

handlers, 193B–194B, 212B

hooks, 200B

341Bobjects, in Views

indexes, 103Bplugins, 193B–194B, 213BViews classes, 154BViews templates, 157B–158Bwidgets, 79B

New content behavior, Panel, 227B

New field setting

changing display of, 34Bwith complex settings, 30Bfor existing content type, 27Bmanagement, 25B

New group

changing field display, 34Bfield management, 25B

new keyword, instantiating constructors, 190B

news sites, using taxonomy terms, 262B

node, 7B

Node add form context, 262B

node author relationship, 272B

Node content, node override, 249B

node contexts

adding, 260B–262Bdefined, 258Bin Panel pages, 258B–259B

Node data type, 26B

Node Reference field type

available widget types, 46Bchoosing, 39Bcreating, 41B–42Bdefined, 26Brelationships and, 272B–273Bworking with, 41B

Node Revision views, 115B

node templates, creating themes, 65B–66B

node view, 115B, 248B–250B

node_add_form context, 258B

node_edit_form context, 258B

node_load( ), 95B–97B

node_revisions table, 7B, 191B

node_save( ), 95B–97B

node_submit( ), 97B

node/NID, 5B–6B

Nodequeue module, 304B–305B

Nodereference module, 14B

nodes

adding as content, 239Badding fields to, 7Bcreating data for CCK fields, 95B–97Bdefault content types, 4B–5Bimportance of, 4Boverview of, 3Bparts of, 5B–7Bsettings for fields, 43B–44Btemplate for, 164Bturning user profiles into, 272B

node.tpl.php, 65B–66B

nofollow option, Link module, 54B

Number fields, 40B, 76B

Number module, 14B

Number of values setting

Date module, 49B–50Bfield for existing content type, 29Bfield with complex settings, 31B–32B

numbers

field types for storing, 40B–41Bsorting string fields with, 106B

numeric data types, 103B, 106B

Oobject-oriented architecture, in

Views, 185B

object-oriented programming, 186B–190B

objects, in Views, 192B–193B

342B online references

online references

add-on modules, 14BCTools, 222BEXPLAIN statement, 181B–182Bgetting help with Drupal, 311Binstalling Drupal, 10B–11BOrganic Groups, 42BPanels package download, 222Bsource control software, 292BViews modules, 304B–307B

option_definition( ),views_object, 194B

Optional setting, exposed filters, 146B

$options array, views_object, 194B

ORDER BY statement, SQL queries in Views, 107B

Organic Groups, 42B

Override setting, Views UI, 124B, 134B

overriding

core node editing pages, 253B–255Bhandlers, 210Bin object-oriented programming,

189B–190Boverriding core display pages

node view, 248B–250Boverview of, 246B–247Btaxonomy, 251B–252Buser view, 252B–253B

PPage caching, anonymous, 182B

Page content type, 4B

Page display

creating, 133B–135Bcreating template with default

message, 168Bdefined, 116Bdisplay-specific settings for, 121B

grouping fields in template, 170Buser feeds with arguments, 143B–144B

Page manager, CTSuite, 222B

Pager settings, Views UI, 120B

Pane settings, in Views, 268B–269B

Panel content screen settings, 238B, 250B, 252B

panel nodes

content editing screen, 238Bcreating, 233B–236Bcreating from Panels dashboard, 226Bediting, 236Boverriding core editing pages,

253B–255Boverview of, 233BPanels package, 222Btab on Panels dashboard, 227B

panel pages

content editing screen, 238Bcontext editing, 258B–259Bcreating, 231B–233Bcreating from Panels dashboard,

226B–227Boverview of, 227B–229Buser interface, 229B–231B

panel panes, adding views to, 266B–267B

panel regions

applying styles, 283B–284BPanel content screen settings, 238Bpoint-and-click layout in Panels,

219B–220Bpanels

access rules for, 244B–246Badding content, 237B–242Bcaching, 242Bconfiguring existing content panes,

243B–244Bmini-panels, 236B–237B

343Bplugins

overriding core display pages,246B–253B

overriding core node editing pages,253B–255B

panel nodes, 233B–236Bpanel pages. See panel pagesPanels dashboard, 225B–227Byour first panel, 225B

Panels dashboard, 226B–227B

Panels in-place editor, 222B–223B

Panels module

arguments in panes, 264B–271Bbrief history of, 217B–218BChaos Tool Suite (CTools), 223Bcontexts. See contextscreating contexts, 221Bexporting, 298B–299Bas modules, 222B–223BPanels package, 222Bpluggable architecture, 221Bpoint-and-click layout, 219B–221Bpurpose of, 217Bpush and pull, 218B–219Brelationships, 271B–273Btheming. See theming Panels

panels_admin stylesheet, 285B

panels_dashboard stylesheet, 285B, 286B

panels_dnd stylesheet, 285B

panels_page stylesheet, 286B

parent directive, plugins, 213B

patches, writing, 313B–314B

Path, Views list page, 112B

path directive, plugins, 213B

Path module, 4B

path setting, Page, 121B

Pathauto module, 308B–309B

paths, node, 5B

patience, reporting issues and, 313B

performance

Basic tab settings, 126B–127Bcaching hooks to improve, 201Bdetermining query, 178B–179Bembedding queries for, 179B–180Bsharing fields between content

types, 36Busing EXPLAIN for query, 180B–182B

permissions

to access published content, 6Bchanging user roles or, 120BContent Permissions module, 14Bmanaging access rules, 244B–246Bnode view, 248Boverriding core display pages, 247Boverriding core node editing

pages, 254BPanels UI settings, 230B–231BUser Reference vs. Node

Reference, 43Bview pane displays, 269B

PHP

CCK’s API using, 75BComputed Field module requiring,

51B–54Bcreating relative dates with, 48B–49Bembedding queries, 179B–180Btemplates and, 156B

plain text

Text field type, 40Bwidget for Email module, 55Bwidget options for Text field type, 46B

players, adding with User Reference, 42B–43B

plugins

handlers vs., 210B–212Bnaming conventions, 193B–194BPanels architecture, 221BPanels styles, 290B

344B plugins

properties and methods for queryobject, 195B–199B

properties and methods forviews_object, 194B–195B

Views, 192B–193B

Views API, 317B–318B

Views classes for, 324B–326B

podcasts, getting help using, 311B

point-and-click layout, Panels, 219B–221B

Poll content type, 5B

polymorphism, in object-oriented programming, 189B

possible_keys, query optimization, 181B

Post date, node content, 6B

PostgreSQL, 101B

posts, nodes as, 3B

pre_execute( ), view execution cycle, 202B

pre_query( ), view execution cycle, 202B

pre_render( ), view execution cycle,203B

<pre> tag, HTML, 165B

Precision setting, widget types, 46B

Prefix setting, widget types, 46B

prepare translation, hook_field( ), 82B

preprocessors, for themes, 164B

presave operation, hook_field( ), 82B

Preview, node override, 250B

preview( ), executing views display, 204B

Preview ,Variants tab of Panel UI, 231B

primary keys, 103B–105B

Print page, Display fields, 35B–36B

printing, default messages for empty fields,167B–169B

procedural architecture, 185B–188B

production, moving from development to,293B–294B

profiles

creating specific user, 308B

turning into nodes, 272B

Promoted to front page option

node content, 6B

Workflow, 21B

properties

field, 24B

query object, 194B–195B

views_object, 194B–195B

Published filter, 124B

Published option

node content, 6B

panel nodes, 236B

Workflow settings, 21B

pulling in needed content, Panel layout, 219B

pushing in needed content, Drupal layout, 218B

Qqueries, SQL

Basic tab settings, 126B–127B

constraining with primary keys,103B–105B

filtering and sorting, 105B–106B

joins and, 106B–107B

in Views, 102B, 107B–108B

query( ) method, query object, 196B

query object

properties and methods, 195B–199B

view execution cycle, 203B

query optimization

determining query performance,178B–179B

development time vs. CPU time in, 177B

embedding queries for, 179B–180B

345BRevision information settings, panel nodes

experimenting with, 183BEXPLAIN statement, 180B–182Bindexing vs. caching, 182Bnot worrying about, 177B–178Boverview of, 177B

Rradio button widget, 45B–46B

records of data. See rows

Reference data type, 26B

Region menu, Flexible panel layout, 277B

registering

handlers, 211Bplugins, 212B

registry, rebuilding theme, 68B

relational databases

emergence of Views for, 102Bfiltering, 105B–106Bjoins, 106B–107Bkeys, 103B–105Brows and fields, 103Bsorting, 106BSQL and, 101Bfrom SQL to Views to human

language, 107B–108Brelationships

adding, 122Bbase tables and, 191B–192Bbuilding SQL queries, 107Bcreating display using, 150B–151Bdesigning page content and layouts

using, 280Bwith foreign keys, 104B–105Bhandlers for, 317Bjoins and, 106B–107Boverview of, 148B–149Bin Panels, 271B–273B

query object, 196B–198Brelating tables to each other,

206B–207Bin taxonomy override page, 251B

relative dates, creating, 48B–49B

release notes, reporting issues, 311B

Remember setting, exposed filters, 146B

render( ) method, view execution cycle, 203B

reporting issues

asking for another’s time and, 314Bbug requests vs. support requests, 312Bchecking other sources, 311B–312Bcontribute back, 314Blife cycle of bugs, 312B–313Boverview of, 309Bpatience, 313Breading documentation, 310B–311Bstaying on topic, 312Bsubmitting complete report,

309B–310Breports, submitting complete, 309B–310B

Required setting

creating field for existing contenttype, 29B

creating field with complex settings,31B–32B

Date module, 49B–50BRescan template files

creating template with default message, 168B

finding new template files with, 156Bgrouping fields in template, 171Boverview of, 165B–166B

reverse links, creating, 43B

revision control, 292B

revision ID (tid) primary key, 103B–104B

Revision information settings, panel nodes, 235B

346B river of news listings

river of news listings, 6B

roles

creating for views, 120BUser Reference and limitations on

user, 43BRow menu, Flexible panel layout, 277B

Row style plugin, 212B

row styles, Views

defined, 114B–115Boverview of, 193Btemplate files, 161B–162B

rows

in relational database tables, 103Breliance on keys, 103B–105Bsimple views with, 129B

RSS feeds

with arguments, 143B–144Bcreating feed view, 135Bdisplay template for, 159Brow style template file, 162B

RSS page, Display fields, 34B–36B

Ssanitize operation, hook_field( ), 82B

Save content type button, 22B

save operation, hook_field_settings( ), 80B

saving views, 142B, 144B

screencasts, for help with Drupal, 311B

select list widget, 45B–46B

SELECT statement, SQL queries, 107B

selection rules, 230B, 247B

Send arguments, Pane setting in Views, 269B

Separator field, table style view, 114B

set_arguments( ), view execution cycle, 201B

set_where_group( ), query object, 198B

Settings tab, Panels dashboard, 226B–227B

Settings tab, Panels UI, 230B

sharing, fields between content types, 29B, 36B–38B

Sheetnode module, 307B

SimpleViews, 307B

single on/off check box widget, 45B–46B

single-value formatters, 88B–89B

site deployment

configuring development environment, 291B–293B

exporting CCK, 295B–296Bexporting panels, 298B–299Bexporting views, 296B–297Bexporting your structures, 294B–295Bhelper modules for themes, 299Bmoving to production, 293–294B

/sites/all/themes directory, basetheme, 60B–61B

slider bar, Flexible panel layout, 277B–289B

slideshows, creating, 305B

Sort Criteria settings

creating simple view, 130Bdefined, 123Buser feeds with arguments, 143B

sort handlers, Views API, 315B–316B

sorting

criteria applied in Views list page,111B

relational database, 106Btables by columns, 114B

source code, CSS in, 285B–289B

source control, configuring developmentenvironment, 292B–293B

special characters, Name and Type fields, 19B

spreadsheets, creating, 307B

347Btabs

SQL (Structured Query Language)

emergence of Views, 102Bfiltering and sorting, 105B–106Bjoins, 106B–107Brelational database basics, 102B–105Brelational databases and, 101Busing CCK’s API, 75Bto Views to human language,

107B–108Bstacking arguments, 144B–145B

stay on topic, in reporting issues, 312B

Sticky, node content, 6B

Sticky at top of lists, Workflow settings, 21B

storage, database, 8B–9B

Story content type, 4B–5B

string context, 258B

string data types, 103B, 106B

strtotime function, PHP, 48B–49B

structures

changing when sharing fields betweencontent types, 36B

configuring development environment, 291B

exporting. See exporting structuresstyle plugins

defined, 212BPanels, 290BViews, 193B, 317B–318B

styles, Panel

applying, 283B–284Bcreating new, 282B–283BCSS in, 284B–285Bother stylistic changes, 289B–290BPanels module supporting, 221Bsharing, 281Busing Stylizer, 280B–281B

styles, View

Basic settings, 119B–120Bcreating simple view, 129B

feed display, 135Bicons for setting, 114Boverview of, 160Bin themes, 61B

stylesheets, 285B–286B

Stylizer

creating new panel style, 282B–283Bdefined, 222Boverview of, 280B–281B

submenu bar, Views Add page, 112B

Submission form settings, content typespage, 19B–21B

Suffix setting, widget types, 46B

suggestions, overriding default theme files, 62B

Summary setting, Variants tab of Panel UI, 230B

Summary tab, Panels UI, 230B

summary views, templates for, 164B

support requests, bug reports vs., 312B

system pages, 228B

Ttable style, Views, 114B, 160B–161B

tables

declaring fields on, 209B–210Bdeclaring in hook_views_data( ),

207B–209Bdefined, 103Bfiltering and sorting fields, 105B–106Bjoins, 106B–107Bkeys, 103B–105Brelating to each other, 206B–207Brows and fields, 103B

tabs

Panels UI, 230BViews left-side, 115B–116B

348B Tag, Views list page title bar

Tag, Views list page title bar, 112B

tags

changing for default view, 113B–114Bediting for default view settings,

117B–118Btasks, 312B

taxonomy

adding term to pane, 263B–264Bchild vs. sibling terms, 264Bcreating list of terms, 115Boverriding core display pages,

251B–252Boverriding title, 264Busing arguments for depth of, 137Busing panels with, 262Busing relationships in panels, 272B

teams, creating, 42B–43B

Teaser

Display fields, 35Bnode content, 7B

teaser view, node view as, 6B

templates, theme

changing, 68B–69Bfield, 61B–64Bnode, 65B–66Boverview of, 59B–60Busing Theme Developer, 70B–71Bviewing with Contemplate module,

71B–73Btemplates, Views

debugging, 167Bdisplay, 159B–160Bgrouping, 169B–175Blisting default, 156B–157Blooking inside, 166B–167Bother, 162B–164Bprinting default messages for empty

fields, 167B–169B

Rescan template files, 165B–166Brow, 161B–162Bview styles, 160B–161Bworking with, 164B–165B

Term views, 115B

term(s) context, 258B

testing

on non-production site, 293B–294Bquery performance, 178B–179B

text, title bar on Views list page, 112B

Text field type

available widget types, 46Bdefined, 26Bworking with, 40B

text field widget, 45B–46B

Text module, 14B

Text processing setting, 31B–32B

Theme Developer, 70B–71B

theme.inc file, /views/themedirectory, 165B

themes

adding files to, 68Bbasics, 59B–60Bchanging parts of, 64B–65Bexcluding fields from, 68Bfield templates creating, 61B–64Bfor fieldgroups, 66B–68Bformatters creating, 61Bhelper modules for, 69B–73Bnode templates creating, 65B–66Bnodes enabling, 4Boverview of, 59Bpreserving base theme, 60B–61Brefining master layout, 218Bsettings in View, 121Btemplates. See templates, themeusing Node Reference, 68B–69B

349Buser interface (UI), Panels

theming Panels

changing layouts, 279B–280B

CSS classes, 289B

CSS in Panels UI, 284B–285B

CSS in source code, 285B–286B

Flexible layout, 275B–278B

identifying particular pane,286B–288B

other stylistic changes, 289B–290B

using Stylizer, 280B–284B

theming Views

classes, 153B–156B

overview of, 153B

template files. See templates, Views

$this variable, OOP, 186B–187B

tid (revision ID) primary key, 103B–104B

Time zone handling field, Date, 49B–50B

title

Basic settings for Views UI, 119B

configuring arguments for, 140B

executing views display for page,203B–204B

node content, 6B

Panel content screen settings, 238B

Submission form settings, 19B

Views list page, 112B

To Date setting, Date module, 49B–50B

Tools pages, Views UI, 125B–126B

topic, reporting issues by staying on, 312B

Total Control Admin Dashboard, 308B

.tpl.php extension, themes

field templates, 62B

node templates, 65B–66B

overview of, 59B

tutorials

creating page, 254B

getting help with Drupal, 311B

Type field

adding fields, 25Bchanging field display, 33B–34BIdentification, 18B–19B

type setting, CRUD API, 92B

type_name, CRUD API, 91B

UUI (user interface), Panels, 229B–231B

UI flow, handlers, 210B

uid (user ID) primary key, 103B–105B

underscores, in machine names, 24B

unformatted style, Views, 114B, 161B

Unlock operator, exposed filters, 146B

updates

hook_field( ), 82Bnode content, 6Bnode override, 250BPanel content screen settings, 238B

Upload module, 4B

URLs

creating readable and memorable,308B–309B

node, 5B–6Bnot passing arguments to blocks with,

144B–145Boverriding using Pane settings in

Views, 269Bpath settings, creating panel nodes,

235Btaxonomy override page and, 251Busing arguments to hide/remove

information in, 137BUse Ajax option, Views UI, 120B

Use panel path option, Pane settings inViews, 268B

user context, 258B

user interface (UI), Panels, 229B–231B

350B user profiles

user profiles

creating specific, 308Bturning into nodes, 272B

User Reference field type

available widget types, 46Bchoosing, 39Bdefined, 26Band relationships, 272B–273Bworking with, 42B–43B

user view

defined, 115Boverriding core display pages,

252B–253BUserreference module, 14B

users, reporting issues. See reporting issues

Vvalidate operation, hooks, 80B, 82B

validation

of arguments, 140BViews UI, 124B

validator plugins, Views, 193B

variables

changing theme with NodeReference, 68B–69B

field template, 63B–64Bvariants

node override, 249B–250Btaxonomy override, 251B–252B

Variants tab, Panels UI, 230B

version control, using source control, 293B

version numbers, Drupal and, 10B

vid (version ID) primary key, 103B–104B

view building flow, handlers, 210B

View Bulk Operations (VBO), 307B

view execution cycle, 201B

view object, Views, 192B

view pane displays, 268B–271B

view_pre_view hook, 202B

.view-content class, 154B

.view-empty class, 154B

.view-filters class, 154B

.view-footer class, 154B

.view-header class, 154B

Views API

base tables and relationships,191B–192B

classes, 318B–326Bdata architecture, 185Bdatabase schema and data hook,

206B–210Bexecuting views display, 203B–204Bexecution-related hooks, 204B–205Bhandlers, 210B–212B, 315B–317Blife cycle of view, 201B–203Bobject-oriented programming,

186B–190Bobjects involved in a View, 192B–199Boverview of, 199B–201Bplugins, 212B–213B, 317B–318B

Views Attach module, 306B

Views Bonus pack, 297B, 305B–306B

Views content panes, CTSuite, 222B, 226B

views data operation,hook_field_settings( ), 81B

Views Datasource module, 307B

Views Datasource plugins, 307B

views directory, 156B

Views Import module, 306B

Views module

Add content modal for, 266B–267BAdd creation page, 115B–116Bbirth of Views 2B, 102BCalendar module requiring, 308Bcreating. SeeViews UI

351Bviews-ui-*.tpl.php file

emergence of, 102Bexporting, 296B–297Bexposed filters, 145B–147Bfilters, 40Bnode, 6Boverview of, 107B–108BPane settings, 268B–269Bquery optimization. See query

optimizationrelationships, 148B–151Bsaving, 142Bsettings, 117B–118Bsimplifying queries with, 107Btemplates. See templates, Viewstheming. See theming Viewsusing arguments. See argumentsViews API. SeeViews API

Views modules

ApacheSolr, 306BFlag, 305BNodequeue, 304B–305BSheetnode, 307BSimpleViews, 306BView Bulk Operations (VBO), 307BViews Attach, 306BViews Bonus Pack, 305B–306BViews Datasource, 307BViews Import, 306BViews Slideshow, 305BViews_or, 304B

Views Slideshow module, 305B

Views UI

Add pages, 112Barguments, 122BBasic settings, 118B–121BBasic tab, 126B–127BBulk Export page, 127B

Convert tab, 127B–128Bcreating feed view, 135Bcreating simple view, 128B–130Bdisplay specific settings, 121B–122Bembedding view within view using

attachments, 135Benabling and changing default view,

113B–114Bfields, 122Bfilters, 123B–124BImport page, 125Bleft-side tabs, 115B–117BList page, 110B–112Blive preview, 125Boverrides, 124Boverview of, 131B–135Brelationships, 122Bsort criteria, 123BTools pages, 125B–127Busing Advanced Help module for, 110Bvalidation, 124BView settings, 117B–118BViews 2 UI vs. original, 109B–110BViews Add page, 115B–116B

Views_bookmark module, 305B

views_embed_view( ), 204B

views_get_current_view( ), 202B

views_handler, 193B

views_handler_filter_in_operatorhandler, 211B

views_object, properties and methodsfor, 194B

Views_or module, 304B

views_plugin, 193B

views-exposed-form.tpl.phpfile, 163B

views-more.tpl.php file, 163B

views-ui-*.tpl.php file, 163B

352B views-view-fields.tpl.php file

views-view-fields.tpl.php file,161B–162B, 166B, 170B–171B

views-view-field.tpl.php file, 164B,168B–169B

views-view-grid.tpl.php file, 160B

views-view-list.tpl.php file, 160B

views-view-row-comment.tpl.phpfile, 164B

views-view-row-node.tpl.phpfile, 164B

views-view.rss.tpl file, 159B

views-view-rss.tpl.php file, 162B

views-view-summary.tpl.php file, 164B

views-view-summary-unformatted.tpl.php file, 164B

views-view-table.tpl.php file,160B–161B

views-view.tpl.php file, 158B–159B

views-view-unformatted.tpl.phpfile, 160B–161B

visibility rules. See access rules, Panels UI

vocabularies

adding taxonomy term to pane,263B–264B

building with taxonomy, 262Bvocabulary context, 258B

WWeb search, for help with Drupal, 311B

WHERE statement

building SQL queries in Views, 107Bwith EXPLAIN for query optimization,

181B–182Bimplementing filters in SQL,

105B–106B

widget types

changing, 47Bcreating custom, 77B–79Bcreating field instances with, 91Bcreating new, 76B–77Bmodules, 85B–87Band settings per field type, 29B, 46B

widget_type setting, 92B

widgets

in CCK at install, 45Bin CCK fields, 76Bconstraining data with, 43B–45Bcreating field with complex

settings, 31BDate module, 48BEmail module, 55BFileField module, 56Boverview of, 29Btemplate, 163B

wildcards

as shortcut for arguments, 140Btaxonomy override page and, 251B

Workflow, content types page, 21B–22B

XXAMPP stacks, installing Drupal, 10B