JETZT ONLINE BESTELLEN
First Edition Januar 2009
ISBN 978-0-596-51580-5
492 Seiten
EUR37.00, EUR37.00
Weitere Informationen zu diesem Buch
Inhaltsverzeichnis |
Kolophon |
Rezensionen |
Inhaltsverzeichnis
- Chapter 1: Drupal Overview
- InhaltsvorschauThis book will show you how to build many different types of websites using the Drupal web publishing platform. Whether you’re promoting your rock band or building your company’s intranet, some of your needs will be the same. From a foundational perspective, your site will have content; be it audio or text or animated GIF images, a website communicates its content to the world. You will also need to manage this content. Although it’s possible to roll your own system with enough knowledge of the underlying web technologies, Drupal makes creating your website; adding new features; and day-to-day adding, editing, and deleting of content quick and easy. And finally, your website will have visitors, and this book will show you many different ways in which you can engage and interact with your community using Drupal.This chapter will begin by providing the hard facts about Drupal: what it is, who uses it, and why they chose it. It will then dive into a conceptual overview, starting with what this ambiguous term “content management” actually means, and how we arrived at building websites this way. And finally, we’ll define and explain the core Drupal concepts that are necessary to understand how Drupal handles its content.Drupal is an open source content management system (CMS) being used by hundreds of thousands of organizations and individuals to build engaging, content-rich websites. Building a website in Drupal is a matter of combining together various “building blocks,” which are described later in this chapter, in order to customize your website’s functionality to your precise needs. Once built, a Drupal website can be maintained with online forms, and without having to change code manually. Drupal is free to use; it has an enormous library of constantly evolving tools that you can use to make your website shine.Drupal is also a content management framework (CMF). In addition to providing site-building tools for webmasters, it offers ways for programmers and developers to customize Drupal using plug-in modules. Almost every aspect of Drupal’s behavior can be customized using these modules, and thousands of them exist that add features from photo galleries to shopping carts to talk-like-a-pirate translators. Most modules have been contributed to the Drupal community and are available for download and use on your Drupal-based website, too. All of the functionality that we’ll be discussing in this book is built using a combination of “core” Drupal and these community-created modules.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- What Is Drupal?
- InhaltsvorschauDrupal is an open source content management system (CMS) being used by hundreds of thousands of organizations and individuals to build engaging, content-rich websites. Building a website in Drupal is a matter of combining together various “building blocks,” which are described later in this chapter, in order to customize your website’s functionality to your precise needs. Once built, a Drupal website can be maintained with online forms, and without having to change code manually. Drupal is free to use; it has an enormous library of constantly evolving tools that you can use to make your website shine.Drupal is also a content management framework (CMF). In addition to providing site-building tools for webmasters, it offers ways for programmers and developers to customize Drupal using plug-in modules. Almost every aspect of Drupal’s behavior can be customized using these modules, and thousands of them exist that add features from photo galleries to shopping carts to talk-like-a-pirate translators. Most modules have been contributed to the Drupal community and are available for download and use on your Drupal-based website, too. All of the functionality that we’ll be discussing in this book is built using a combination of “core” Drupal and these community-created modules.It’s noteworthy to acknowledge Drupal’s community; the wetware element of Drupal is often cited as one of Drupal’s biggest assets. When Drupal 6 was released in February 2008, more than 700 members of the community contributed code to the core component of the software. More than 2,000 developers maintain contributed modules, with countless more helping with testing, documentation, user support, translations, and other important areas of the project. Those familiar with evaluating open source platforms will attest to the importance of a thriving community base.Over the last couple of years, the popularity of Drupal has exploded, to the point where some pretty big names have taken notice. Media companies such as MTV UK, Lifetime, and Sony BMG Records are using Drupal as a means of building loyal communities around their products. Print publishers such as theEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- A Brief History of Content Management
- InhaltsvorschauBefore looking any closer at Drupal, let’s take a brief trip back in time to the days before content management systems. To understand how Drupal and other CMS packages simplify your work, we’ll take a look at how things worked when the Web was young.Back in the dim recesses of time (the 1990s, for those who remember zeppelins and Model T cars), web pages were nothing more than simple text files nestled comfortably into folders on a server somewhere on the Internet. With names like index.html, news.html, about_us.html, and so on, these files were viewable by anyone with a web browser. Using the HTML markup language, these files could link back and forth to each other, include images and other media, and generally make themselves presentable. A website, as the hipsters of that day would explain, was just a collection of those files in a particular folder, as pictured in .
Figure : A historical look at website structureThis system worked pretty well, and it made sense. Every URL that a user on the Internet could visit corresponded to a unique .html file on the web server. If you wanted to organize them into sections, you made a folder and moved the files into that folder; for example, http://www.example.com/news/ would be the address to the “News” section of the site, and the 1997 newsletter would be located at http://www.example.com/news/fall_1997_products.html. When the webmaster (or the intern) needed to fix a problem, they could look at the page in their web browser and open up the matching file on the web server to tweak it.Unfortunately, as websites grew in size, it was obvious that this approach didn’t scale well. After a year or so of adding pages and shuffling directories around, many sites had dozens, hundreds, or sometimes even thousands of pages to manage. And that, friends, caused some serious problems:- Changing the site’s design required an enormous amount of work
- Formatting information, layout, and other site design was done individually on every single page. Cascading Style Sheets (CSS) hadn’t yet taken the web world by storm, so tasks as simple as changing the site’s default font required (that’s right) editing
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - How Does Drupal Work?
- InhaltsvorschauAt a conceptual level, the Drupal stack looks like . Drupal is a sort of middle layer between the backend (the stuff that keeps the Internet ticking) and the frontend (what visitors see in their web browsers).
Figure : How Drupal and its conceptual layers fit with other layers of a websiteIn the bottom layers, things like your operating system, web server, database, and PHP are running the show. The operating system handles the “plumbing” that keeps your website running: low-level tasks such as handling network connections, files, and file permissions. Your web server enables that computer to be accessible over the Internet, and serves up the correct stuff when you go to http://www.example.com. A database stores, well, data: all of the website’s content, user accounts, and configuration settings, in a central place for later retrieval. And PHP is a programming language that generates pages dynamically and shuffles information from the database to the web server.Drupal itself is composed of many layers as well. At its lowest layer, it provides additional functionality on top of PHP by adding several subsystems, such as user session handling and authentication, security filtering, and template rendering. This section is built upon by a layer of customizable add-on functionality called modules, which will be discussed in the next section. Modules add features to Drupal and generate the contents of any given page. But before the page is displayed to the user, it’s run through the theme system, which allows modification and precise tweaking for even the pickiest designers’ needs. The theme system is covered in detail in .The theme system outputs page content, usually as XHTML, although other types of rendering are supported. CSS is used to control the layout, colors, and fonts of a given page, and JavaScript is thrown in for dynamic elements, such as collapsible fieldsets on forms and drag-and-drop table rows in Drupal’s administrative interface.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Getting Help
- InhaltsvorschauIt’s easy to focus only on the functionality you get for free with an open source application. But it would be a mistake to forget that the Drupal community itself is another vital building block for your website!As you go through the hands-on examples in this book, you might run into some issues particular to your installation. Or, issues might be created as new versions of modules are released. Fortunately, the Drupal community has a wealth of resources available to help troubleshoot even the nastiest error you might encounter:
- The Drupal handbooks at http://drupal.org/handbooks contain a wealth of on everything from community philosophies to nitty-gritty Drupal development information.
- The Getting Started guide at http://drupal.org/getting-started contains some particularly useful information to help get you through your first couple of hours with Drupal.
- The Troubleshooting FAQ at http://drupal.org/Troubleshooting-FAQ has useful tips and tricks for deciphering error messages that you might encounter.
- For more one-on-one help, try the Support forums at http://drupal.org/forum/18 for everything from preinstallation questions to upgrade issues.
- If your question is about a specific module, you can post a “support request” issue (or a “bug report” if it’s a blatant problem) to the module’s issue queue, which reaches the module’s maintainer. A helpful video on how to maneuver around the Drupal.org issue queues is available from http://drupal.org/node/273658, and issue queues are also discussed in .
- There’s a #drupal-support IRC channel on irc.freenode.net if you’re more of the chatty type.Unlike #drupal-support, the #drupal channel on irc.freenode.net is not a support channel. This channel is a place for developers to get coding help and for other contributors to actively brainstorm and discuss improving the Drupal project as a whole. By all means, participate here to get involved in the community, and ask your coding-related questions, but remember that questions like, “Where is the option I toggle to do this?” and “What module should I use for that?” will make people a bit cranky.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Conclusion
- InhaltsvorschauIn this chapter, you’ve learned what Drupal is. You have seen the history of websites and content management to better understand the challenges inherent in keeping a growing site healthy. We’ve examined the conceptual building blocks that Drupal uses when building next-generation sites, as well as how they fit together. We’ve also seen numerous ways to get help if you’re stuck. In the following chapter, we’ll put these pieces together to make your first Drupal website!Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Chapter 2: Drupal Jumpstart
- InhaltsvorschauThis chapter, intended for readers who are new to Drupal, provides a tour of its capabilities, as well as definitions for its sometimes obscure terminology, by demonstrating how Drupal can be used to build a simple website. Readers who are familiar with Drupal already may still want to skim this chapter, as later chapters will assume knowledge of all content covered here. By the end, you’ll understand how to perform administrative tasks in Drupal, such as configuring modules, working with content types, and setting up site navigation.This chapter assumes that you already have Drupal up and running. For assistance, check out , as well as the helpful online Getting Started guide at http://drupal.org/getting-started.This chapter introduces the following modules:
- Node (core)
- Allows you to post content and create your own content types
- User (core)
- Handles allowing users to log in, as well as Drupal’s robust roles and permissions systems
- Block (core)
- Adds dynamic sidebars and other supplementary content
- Menu (core)
- Handles management of a Drupal website’s navigation
- Path (core)
- Allows entry of friendly URLs such as http://www.example.com/about rather than
- Administration Menu (http://drupal.org/project/admin_menu)
- Provides a dynamic drop-down navigation menu to speed administrative tasks
- Contact (core)
- A simple form that site visitors may use to send inquiries to website owners
- Blog (core)
- Provides quick and easy multiuser blog functionality
- Taxonomy (core)
- A powerful classification and categorization system
- Filter (core)
- An important and often misunderstood module that is key to Drupal security
- FCKeditor (http://drupal.org/project/fckeditor)
- A “What You See Is What You Get” (WYSIWYG) editor that allows people without HTML knowledge to create rich website content
- IMCE (http://drupal.org/project/imce)
- An add-on module that can work with editors such as FCKEditor to make it easy to add images to website content
The completed website will look as pictured in and at http://jumpstart.usingdrupal.com.
Figure :Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- InhaltsvorschauMom and Pop, Inc., is a small organic grocery store in the midwestern United States run by its co-owners, Jeanne and Mike. Their current web presence is a long, endlessly scrolling static HTML page that lists general information such as the background of the company, its hours and location, and what promotions are currently running.Neither Mike nor Jeanne is comfortable editing the code in the page by hand, so in order to update the web page content each week, they currently pay their next-door neighbor Goldie to hand-edit the page. Because this sort of manual labor is tedious, it usually takes a long time for her to get around to doing it. As a result, the site is frequently out of date and not doing much other than costing money to keep it online.Mike and Jeanne would like to have a new, fresh site that they can manage themselves by filling out web forms rather than editing code. They need some static pages, such as a Home and an About page, along with a place to showcase special weekly deals. They would also like a contact form to receive inquiries from customers.Mike and Jeanne also would like a blog where they can talk about things like in-store events or general goings-on in the community. Visitors to the site should be able to comment on blog entries, with anonymous visitors’ comments going into an approval queue first.Neither Mike nor Jeanne is a coder, so it’s important that the content be easy to edit for someone without knowledge of HTML. And finally, the site should have some basic branding—site logo and colors—so that the site “feels” like their own.Goldie’s been hearing a lot about this “Drupal” thing lately, so she decides to give it a shot for this project.The ” section of each chapter will discuss, compare, and contrast various options for fulfilling the client’s needs in Drupal, and how the authors came to decide on the solutions selected in the chapter.
Basics
Almost all of the functionality required by Mom and Pop, Inc., is provided by the bundle of features that comes as part of the main Drupal software download, called the Drupal “core.” Drupal’s Node module has the built-in ability to create various types of content on the site, including static pages, which work great for the Home and About pages. We’ll use the core Path module to give these pages nice and descriptive URLs such asEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Content Management
- InhaltsvorschauDrupal’s primary function is to enable website administrators to manage their own content. This section offers a tour of some of the most basic tools for content management in Drupal.
Figure : A list of available content typesAs discussed in , each piece of content in Drupal, from a static page to a blog entry or a poll, is called a node. Drupal comes with two content types by default: Page, intended for static content such as an “About Us” page, and Story, intended for content that will be frequently posted, such as news articles. But like most things in Drupal, content types are fully configurable. shows the “Create content” page on a typical Drupal site with several content types available. This page is found under the path “node/add” (http://www.example.com/node/add).As mentioned in the Preface, future navigation instructions within Drupal will use the shorthand “Create content” (node/add).shows an example of a typical node form, which is used to add or edit a piece of content. Each node has a Title, which identifies the node in content listings and controls the title of the web page it’s on, and most nodes also have a Body field, which holds its primary content. Although the extensive options at the bottom of this form may seem daunting, don’t worry. A general site visitor won’t have permissions to change Menu settings, Authoring information, or other settings, so they simply do not show up on the form for these users.
Figure : A typical node form in DrupalPeople coming to Drupal with web development experience with a tool such as Dreamweaver often get confused by Drupal’s notion of a “Page.” Web development tools refer to the contents of an entire browser window from the logo in the upper-left corner down to the copyright notice in the lower-right as a “page,” but in Drupal creating a new “Page” node only affects the content of a given web page: its title, its body, and any additional properties such as a byline or rating.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Content Management
- InhaltsvorschauOut of the box, our wonderful Drupal site, pictured in , looks pretty bare. Adding some content with information about Mom and Pop, Inc., will do wonders to make this actually start looking like a website. In this section, we’ll create a couple of simple pages—the About Us page and the Home page—and begin to build our website’s navigation. We’ll also add a few blocks, for extra pizzazz.
Figure : Drupal, after a fresh install- First, we’ll create the site’s Welcome page, which we’d like to use as the home page of the site. Go to Create content→Page (node/add/page).
- Enter the settings provided here in and . Because this is a static page, we’ll also place it into our primary navigation menu using the settings provided by the Menu module.
Table : Home page values SettingValueTitleWelcome to Mom and Pop, Inc.Menu settings- Menu link title
Home- Parent item
<Primary links> (default)- Weight
0 (default)BodyWelcome to our website! We hope you enjoy your stay!
Figure : Creating the site’s home page- Click Save to create the page. Once the page is created, make note of the path in your browser’s address bar. It should look like http://example.com/node/1. Write down the part that comes after the http://www.example.com/, which should be node/1. This is the node ID of our page—we’ll need it later.
- Next, we’ll make our About Us page, which uses the same steps. Go to Create content→Page (node/add/page).
- As with any node we create in Drupal, we’ll enter a title and a body. Enter the settings from and then click Save.
Table : About page values SettingValueTitleAbout UsMenu settings- Menu link title
About Us- Parent item
<Primary links> (default)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Modules
- InhaltsvorschauAs discussed in , modules allow you to turn on and off functionality within your Drupal website. There are two types of modules: “core” modules, which come with Drupal itself, and “contributed” modules, which are provided for free by the community and available for download from Drupal.org. This section discusses you need to know about modules.The module administration page, available from Administer→Site building→Modules (admin/build/modules) and depicted in , is where Drupal provides configuration options for your website’s functionality. Related modules are grouped together within fieldsets, and each module entry contains a description and an indication of which version is currently running on the site. This version information can be extremely useful when troubleshooting problems.
Figure : Module administration pageModules may be switched on and off by toggling their Enabled checkboxes, which allows you to custom-tailor the functionality of any Drupal site to its unique needs, without bogging it down with needless overhead.A module might also have dependencies. That is, it might require one or more other modules in order to work properly. For example, the Forum module requires both the Comment and Taxonomy modules to be enabled before it can be enabled. If you forget to do this, a confirmation screen will appear asking you whether to enable the required modules in order to proceed.Nearly all modules also have one or more administration pages associated with them for configuring various settings. Most often, these are found under Administer→Site configuration (admin/settings) or Administer→Site building (admin/build). Because modules can easily add additional administration pages, we recommend navigating to the Administration (admin) main page and clicking the “By module” tab (admin/, as pictured in , to view all administrative options broken down module by module. This is a best practice to follow after installing a new module.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Working with Modules
- InhaltsvorschauThe easiest way to wrap your head around how modules work is to try installing and configuring a couple of them. This section will cover how to install, enable, and configure two modules: Path, a module that’s built into Drupal core, and Administration Menu, which is a contributed module that may be downloaded from Drupal.org.In the earlier hands-on section (”), we created an “About Us” page and a “Home” page and added them to our site’s menu. But if you return to those pages, you’ll see that the URL is something like http://www.example.com/about?. Wouldn’t it be great if we could instead give these pages nice search URLs like http://www.example.com/node/1? We can, with Drupal core’s Path module.The Path module allows us to specify human-readable URLs, referred to as URL , which mask Drupal’s default way of naming paths:
- Begin by navigating to the modules administration page at Administer→Site building→Modules (admin/build/modules).
- Under the Core – optional package, check the Enabled checkbox next to the Path module, as pictured in , and click the “Save configuration” button at the bottom of the form.
Figure : Enabling the Path module- Click on the About Us page in the menu, and click the Edit tab.
- Toward the bottom of the form, you’ll see a new fieldset called “URL path settings,” as pictured in . Enter about as the path, and click Save.
Figure : Entering a path alias for a node- Now, if you click on the About link in the menu once more, you should see the URL change to http://www.example.com/about.
- Repeat the previous steps to add a URL alias for the Home page as well, using home for the “URL path settings.”
Setting URL aliases by hand can be tedious. The Pathauto module (go to http://drupal.org/project/pathauto), covered in , allows you to set up customized rules that automatically generate friendly URLs for all of your website content (Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Access Control
- InhaltsvorschauOne of the most powerful features of Drupal is its rich, fine-grained access control system, based around the concept of users, roles, and permissions.
- User
- A visitor to the website. A user can be anyone: a casual visitor to the website, your company’s president who’s blogging on the site every day, your system , or someone who doesn’t work for your company at all but is still adding content (as with a social networking site).
- Role
- A group to which users can be assigned. Roles can be something like “administrator” or “sales team member.” Drupal comes with two roles by default—“anonymous user” (for all users who have not logged in) and “authenticated user” (for all logged-in users)—but you can create as many different roles as you want.
- Permission
- Something that users within a role can (or can’t!) do on the website. Each module can specify its own list of permissions that may be assigned. Examples of permissions are “access site content” and “edit own blog.” If a user does not have proper permissions to do something on the website, he’ll receive an “Access denied” error page when trying to access the given functionality.
You can customize the “Access denied” and “Page not found” error pages at Administer→Site configuration→Error reporting (admin/settings/error-reporting).It’s worth sitting down at the beginning of each project and really thinking through what types of users will visit the site and what they’re going to want to do. Those will correspond to roles and permissions in the system. Try to think of your users in terms as broad as possible. Particularly on small sites and at small organizations, you might be tempted to create a role for each person (e.g., “Greg’s role”). But this gets extremely cumbersome, not to mention confusing, when Susan later replaces Greg. Rather, think of what Greg will be doing on the website, such as site configuration, upgrades, and backups, and name the role after those tasks (e.g., “site administrator”) instead.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Creating Roles
- InhaltsvorschauEarlier, we talked about Drupal’s access control system, and how it’s composed of users, roles, and permissions that map to who is going to use the site and what they’re going to want to do on it. Let’s spend a moment brainstorming about Mom and Pop, Inc.’s needs in this area.This site will have four types of users:
- Passing visitors, who will basically only be able to read and search content, comment on news items once their content has been approved, and send mail with the contact form. This will map to the built-in “anonymous user” role in Drupal.
- Customers, who will log into the site and can comment on content, but aren’t able to actually post news items themselves. Because they will be logged in, we’ll use the built-in “authenticated user” role for customers.
- The store owners Mike and Jeanne themselves, who will handle writing content and some of the smaller day-to-day administration of the website. They’ll need to be able to create and manage content, view logs and statistics, and change certain website settings when required. However, because they’re not extremely savvy, the more advanced options should be hidden. We’re going to call this role “editor,” as they will be largely adding and editing content on the site.
- Finally, Goldie is the webmaster, who will actually build the site, as well as look after the more technical details for Jeanne and Mike. This will entail things like installing and upgrading modules, and configuring advanced website settings. Although she could just do everything as User 1, at some point she might want to bring on another family member to take over her duties, so it pays to be forward-thinking and make a role for this purpose. We’ll call this role “site administrator.”
These standard four roles are the same ones we’ll use in all future chapters. On your own Drupal site, you can have as many or as few roles as you’d like.With that, we can begin setting up our access control:Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Configuring Permissions
- InhaltsvorschauNow that we have roles in place, let’s assign some permissions to control who can do what on the site:
- Head to Administer→User management→Permissions (admin/user/permissions).
- This screen, as seen earlier in , is massive, and there’s a lot to do here. We’ll break this enormous table down one module at a time.
- Remember when we enabled the Administration Menu module in the previous section? Right now, User 1 is the only person who can see the useful drop-down navigation bar at the top. Let’s enable this feature for both site administrators and editors, using the settings in . The “access administration menu” permission controls visibility of the admin bar, and the “display drupal links” specifies whether resources on Drupal.org should also be part of the menu. This is a useful permission for Goldie, but not so much for Mike and Jeanne, as they won’t be troubleshooting site administration issues.
- shows the permissions for the Block module, which defines two permissions: “administer blocks” and “use PHP for block visibility.” The administer blocks permission allows the users within a role to select which blocks are enabled and where they appear on the page, as well as to create new blocks. As this would be a useful thing for Mom and Pop to do, we’ll assign that permission to the editor role. We’ll also assign it to the site administrator role, because it is an administrative task. However, we are not going to assign the use of PHP block visibility to any role. This is an advanced feature with security implications and only User 1 should be able to access it.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Contact Form
- InhaltsvorschauLet’s put together everything we’ve learned so far and get that contact form, pictured in , set up.
Figure : A contact form for the website- First, enable the Contact module. Go to Administer→Site building→Modules (/build/modules), check the box next to “Contact module” under the package, and click “Save configuration.”
- Next, we need to set up the contact form’s settings. Go to Administer→Site building→Contact form (admin/build/contact).
- Click “Add category” (admin/build/contact/add), enter the settings from as pictured in , and click Save.
Table : Contact category settings SettingValueCategoryWebsite feedbackRecipients(enter your email address)Auto-replyThanks for sending feedback about our website! We will respond to your inquiry shortly.
Figure : Settings for the website feedback contact form category- Repeat the previous steps to enter another category for “Sales opportunities.” You can set this category to go to a different email address, if you’d like.
- Next, we’ll want to add a link in the website navigation to the contact form for visitors. This module happens to conveniently provide us with a menu item all ready to use, but it is not enabled by default. Anytime a module provides a menu item for you, it will always appear in the Navigation menu by default. We can easily move it to wherever we want, though. Go to Administer→Site building→→Navigation (admin/build/menu-customize/navigation).
- Find the “Contact (disabled)” menu item in the list (it will be grayed out). Click the “edit” link for it.
- Enter the settings from , and click Save.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Taxonomy
- InhaltsvorschauWe have now played around with almost all of Drupal’s basic site-building tools. There’s just one more concept to cover in order for us to complete the functionality of Mom and Pop, Inc.: Taxonomy.If you’re new to Drupal, you’ve probably wondered what “Taxonomy” is—the word pops up all over the place, and it can sound a bit mysterious. Have no fear! It’s just a technical term for a way of organizing and classifying things. If you’ve sorted your family photo album, filed your email in folders, or argued with a friend about whether a band is punk or ska, you’ve already worked with taxonomies!Creating a taxonomy for your site starts when you identify what kinds of content you’ll have, and how it can be described. Photographs, for example, might be classified by the subject matter, the location in which they were taken, or even the predominant color in the picture. In Drupal, these categories are called vocabularies. Each vocabulary contains specific terms (like Mountains or Automobiles or Pets) that can be used to describe content. Whenever you post a photograph, a music review, or a blog entry, you can select the terms that match it.Drupal supports three kinds of vocabularies: simple lists of terms, organized hierarchies of terms, and “free tagging” vocabularies that allow you to define new terms as you post new content. Each is useful in different situations. shows an example of how each type of vocabulary might be used on a product content type.
Figure : Examples of taxonomy typesFor the librarians in the house, Drupal’s taxonomy system also supports more advanced features of taxonomies such as synonyms, related terms, and multiple parent hierarchies. Whew!After submitting a piece of content, any terms it has attached will appear as links on the node page, as displayed in . Each of these links displays a page listing all content to which that term has been applied, along with an RSS feed that visitors can subscribe to in order to receive notifications whenever new content with that term attached is posted.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Blog
- InhaltsvorschauIt’s time to put the last piece of site functionality in place: setting up blogs for Jeanne and Mike. We want blog posts to be categorized according to broad topics: is the blog post about in-store events, special deals, or general community information? But blogs should also allow “tagging”—attaching free-form keywords that don’t fit in well with the major topics.
- Go to Administer→Site building→Modules (admin/build/modules) and enable the core Blog module. Click “Save configuration” when finished. This will add a new content type called “Blog entry” for Mike and Jeanne to post.
- As a general best practice, anytime we enable a new module, we should go to the Administer→User management→Permissions (admin/user/permissions) screen to configure the module’s access control. We can take a look to see what permissions have been added to the list, but in our case we don’t need to set any of the new permissions here. Both Jeanne and Mike already have the “administer nodes” permission, which automatically grants them the rights provided by the Blog module, so we can leave it alone.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Content Moderation Tools
- InhaltsvorschauWhen opening the floodgates for your users to become active participants in content creation, one of the inevitable things that comes up is how to handle the issue of content moderation, that is, ensuring that abusive, vulgar content and unsolicited advertising or spam is kept off the site and stays off.You can help prevent this type of content using a two-tiered approach: automated spam detection and manual spam prevention.There are multiple tools that specialize in automated spam detection, but two in particular are worthy of mention in a Drupal site context: Akismet and Mollom. Each of these tools is a web service and requires an “API key,” a specific random string of characters, to communicate between a website and the central reporting server.Akismet (http://akismet.com) is a service created by Matt Mullenweg, creator and project lead of the blogging platform WordPress. It scans through the content of your site’s comments and “trackbacks” (excerpts of posts on other blogs that link to yours), and based on its analysis of millions of other blogs’ content, will either delete the content if it’s spam, or send it on through if it’s clean (or “ham”). Installing the Akismet module allows you to tap into the collective intelligence of millions of other blogs using the service. Chances are good that by the time a spammer trains its automated posting scripts on your website, Akismet already knows how to fingerprint the attacker and will delete the comment before it’s seen by anyone on your site. And if not, Akismet provides the ability to manually mark the content as spam, and uses that data to learn from its mistakes. Akismet has been around since 2005 and has captured over seven billion spam comments, making it a tried and tested solution. The Akismet module is available from http://drupal.org/project/akismet, and an API key for the service may be obtained from http://wordpress.com/api-keys/.Mollom (http://mollom.com) is a newer service started by Benjamin Schrauwen and Dries Buytaert, creator and project lead of Drupal. It performs a very similar service to Akismet by automatically scanning the content of comments and preventing obvious spam from even being posted to the website. Like Akismet, your website benefits from the collective intelligence of every other website that has a Mollom plug-in installed, and Mollom is also compatible with many different content management systems and programming languages.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Spotlight: Themes
- InhaltsvorschauThemes control the look of your Drupal site. It’s not enough to get a site functionally working—it also has to feel like your own, and has to be distinguished from other sites out there.Drupal.org has a large repository of free themes that have been uploaded by contributors. You can find a listing of these themes at http://drupal.org/project/Themes, or you can try them out “live” at http://themegarden.org.The quality of the themes in the Drupal repository varies greatly. These themes have been created for a wide variety of purposes and needs by contributors with a broad range of programming and design skills. Download several themes and be sure to read their README.txt files to determine how to best use them. Many of these themes can be used as a starting point from which site administrators can customize their own site-specialized presentation.Several companies offering for-purchase themes have also emerged in the Drupal ecosystem. These themes tend to be higher quality, a bit more “bullet-proof,” and may allow for easier customization by administrators.Installing a theme requires almost exactly the same process as installing a module. Download the theme’s .tar.gz file from its project page and extract it. Place the theme’s directory into the sites/all/themes directory, and your new theme should appear on the Themes administration page in your Drupal installation, as shown in .As with modules, themes written for Drupal 5 are not compatible with Drupal 6 and vice versa. Drupal 5 themes will not appear on this page if you are running Drupal 6.Themes can be switched on from the Themes page at Administer→Site building→Themes (admin/build/themes), shown in .
Figure : The Themes administration pageMost administrators can just ignore the “Enabled” column—the “Default” column is what actually defines the theme that all users without permission to select themes will see. Enabling our new theme is as simple as selecting it in the Default column and hitting the “Save configuration” button at the bottom of the form. The new default theme should affect the site design immediately.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Branding the Site
- InhaltsvorschauNow, it’s time to make the site look less like Drupal and more like Mom and Pop, Inc. This section will walk through configuring a theme in order to customize the look and feel of a site.
- Head to Administer→Site building→Themes (admin/build/themes), and ensure that the Default radio button is selected for the Garland theme. Click the “Save configuration” button. You should see your site switch to the Garland theme, if it wasn’t using it already.If the newly selected theme does not appear immediately, here are a couple of things to check:
- Is the site using an administration theme? If so, all administration pages will show up in the administration theme. You’ll need to click to something like your site’s home page to see the changed theme.
- Are there multiple themes enabled on the site, and does your user account have “select different theme” permissions? If so, either uncheck the “Enabled” checkboxes for unused themes on the Themes page or visit the “Edit” tab on the “My account” page and select the new theme.
- Click the Configure tab (admin/build/themes/settings) to configure the Global settings, which apply to all themes.
- Under “Logo image settings,” upload the mom_and_pop_logo.png image in the assets/ch02-basic folder in the book’s source code. Upon saving the form with the “Save configuration” button, you should see the new logo appear in the upper-left corner. But it looks absolutely horrendous on that blue background!
- Click the Garland tab (admin/build/themes/settings/garland) to access the Garland-specific theme settings, which include an integrated color-picker from the Color module.
- Choose a color scheme that is pleasing to the eye and complements the logo. Be creative! When you’re happy with the results, click “Save configuration.”
- The page looks a little cluttered now with both the site logo and the “Mom & Pop, Inc.” site name at the top. Let’s turn off the visibility of that feature. Uncheck “Site name” in the “Toggle display” fieldset, and click “Save configuration” again.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Content Editing and Image Handling
- InhaltsvorschauWe now have a site with all the functionality that Jeanne and Mike asked for, access control configured properly, and a slick new look, complete with a custom color scheme and fancy new logo. However, one final piece remains: streamlining the content editing process, and allowing easy image uploads.As mentioned previously in the chapter, by default Drupal’s content entry is done with HTML. Like most earthlings, Mike and Jeanne aren’t fluent in code, so it’s important that they be able to format their content and add images without it. Not surprisingly, a number of community solutions to this issue have cropped up over the years:
- Toolbars
- Some users can use HTML fine if they’re given a toolbar that inserts the tags on their behalf. The BUEditor module (http://drupal.org/project/bueditor), pictured in , is an example of a module that provides such a toolbar.
Figure : The BUEditor module provides a toolbar to assist with HTML- Text-to-HTML translators
- Modules such as Textile (http://drupal.org/project/textile) or Markdown Filter (http://drupal.org/project/markdown), covered in , provide the ability to take simple text such as
**bold**and transform it into its HTML equivalent (<strong>bold</strong>). This syntax, once learned, is much easier and faster to type in than raw HTML. - What You See Is What You Get (WYSIWYG) editors
- WYSIWYG editors not only provide a toolbar, but also display the formatting directly in the text area, looking similar to a word processor, as pictured in . There are several Drupal modules that offer integration with WYSIWYG editors, but the most popular are TinyMCE (http://drupal.org/project/tinymce) and FCKeditor (http://drupal.org/project/fckeditor).
Figure : FCKeditor module displaying an editing formThe further away from raw HTML entry you go, the greater chance there is that the “smart” WYSIWYG editing plug-in will get confused and choke on complex formatting. Subtle differences between web browsers, incompatibilities with the CSS that you’re using to customize your site, and other problems are all possible—if not common. Many times, the trade-off is still worth it, because the users of your site aren’t interested in learning the subtleties of HTML to make something bold or italic. But due to the pitfalls, it’s often best to ask, “Does my site need this?” before dropping in a “pretty” HTML editor module.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Input Formats and Filters
- InhaltsvorschauYou may have noticed this funny fieldset on node and block body fields that we keep ignoring called “Input formats,” pictured in . The input format that is selected for the content will affect how that content is displayed on the site. Input formats are an important security feature of Drupal, so it pays to understand them. An input format will “scan” your content and make HTML formatting changes to it before sending it to the browser for display. Each piece of content will be associated with an input format so that Drupal always knows what it is looking for and modifying, on a case-by-case basis.
Figure : Input formats attached to a node bodyNote that whichever input format is marked as “Default” on the administration screen will be accessible to all users, including anonymous visitors. As a general rule, the default input format should always be Filtered HTML.In , there are only two choices, Filtered HTML and Full HTML. These are the two default input formats that come with Drupal core. Sites can have several input formats to choose from; some can be provided by modules, like PHP filter, and you can also create your own custom formats. Input formats are restricted by roles so that you can allow everyone to use one input format, like Filtered HTML, but also make an advanced input format, like Full HTML, available only to your most trusted users, like the site administrator role.If a user reports a node’s edit tab as mysteriously gone, check its input format. Drupal will disallow editing on content if the user’s role does not have access to the input format of the content. This behavior can be used to your advantage if you want to protect certain pages from editing by users who would otherwise have access to do so.Input formats are composed of filters. shows the list of filters that are used in the Filtered HTML input format. The filters are doing the real work; the input format is simply a group of filters. A filter modifies content and outputs the proper HTML for display. Examples of filters include “Line break converter,” which transforms new lines (carriage returns) intoEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Setting Up FCKeditor
- InhaltsvorschauBefore we dig into the editor’s setup, we will need all of the modules and requirements. You should download the latest versions of the FCKeditor and IMCE modules as you did earlier for the Administration Menu module in the “ section. The project page for FCKeditor is located at http://drupal.org/project/fckeditor and the project page for IMCE is at http://drupal.org/project/imce. Once you have the modules in place, we still aren’t quite done yet, because the FCKeditor module doesn’t actually contain the FCKeditor software itself. This is because the FCKeditor software comes from its own, external open source website and community that develops and maintains it, outside of the Drupal community.
Figure : The Download link on the FCKeditor website
Figure : File download links for FCKeditor
Figure : Directory structure for the FCKeditor website- Go to http://www.fckeditor.net and click the Download link in the upper-right navigation area on the site, as shown in .
- The first version listed in the Download section will be the latest version of . In , this is FCKeditor 2.6.3. Under the version listed are two links that you can use to download. The only difference is in the type of compression used, zip or tar, so you can use either. Click the link listed for the version you want. In , this would be FCKeditor_2.6.3.zip or FCKeditor_2.6.3.tar.gz.
- Once you have the file downloaded, go ahead and extract it. You should be presented with a folder named fckeditor.
- You need to copy this folder into your FCKeditor module folder. There is already an empty folder with this name in there, so you want to replace that folder with the new one you just extracted. All of the similar names can get quite confusing, so make sure that your finished result has the following directory structure leading down to the FCKeditor software’s main PHP file (also shown in ):
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauThis chapter provided an overview of the major functionality of Drupal by building a small website. We installed Drupal, we created some simple content and content types, we got a taste of the taxonomy system, we set up a contact form, we worked on how to configure Drupal’s theme settings to customize a site to a particular look and feel, and we set our editors up with a WYSIWYG editor and image handling so that they can make their posts look just the way they want without knowing HTML.Here is a list of modules were referenced in this chapter:
- Administration menu: http://drupal.org/project/admin_menu
- FCKeditor: http://drupal.org/project/fckeditor
Here is a list of links that we referenced in this chapter:- Drupal core download: http://drupal.org/download
- Module downloads: http://drupal.org/project/Modules
- Theme downloads: http://drupal.org/project/Themes
- FCKeditor website: http://fckeditor.net
- Drupal system requirements: http://drupal.org/node/270
- Drupal version information: http://drupal.org/handbook/version-info
- Drupal.org handbooks: http://drupal.org/handbooks
- Getting Started guide: http://drupal.org/node/258
- Troubleshooting FAQ: http://drupal.org/Troubleshooting-FAQ
- Support forum: http://drupal.org/forum/18
- XAMPP (local web server): http://www.apachefriends.org/en/xampp.html
- MAMP (local web server): http://mamp.info/en/download.html
- StuffIt Expander: http://my.smithmicro.com/mac/stuffitexpander
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 3: Job Posting Board
- InhaltsvorschauThis chapter outlines the two most powerful features in Drupal. Yes, we’re saying outright that the two most powerful features are the Content Construction Kit and Views. The Content Construction Kit (commonly abbreviated CCK) allows you to create forms containing a variety of fields—such as checkboxes, select lists, image uploads, and many others—all without writing a line of code. The Views module is the natural counterpart to CCK, letting you get data out of your site rather than into it. Views allows you to create pages and blocks that pull data back out and display it to your visitors. Want a paged table showing product details that can be sorted by price or manufacturer? You can build it with CCK and Views. Want to display a block that lists the albums of a particular artist in a grid as a set of album cover thumbnails? You can build it with CCK and Views. Anywhere there’s a list of content on your website (and most websites are almost all just lists of content in one form or another), CCK and Views are the two key modules you need.CCK and Views form the foundation of nearly every other project in this book and most of the Drupal-powered websites on the Internet. We’ll cover how to set up a new content type and customize the node form so that you can add any type of field for inputting data. We’ll configure a site that allows the creating of job openings, and then we’ll build an interface for browsing though available jobs.This chapter introduces the following modules:
- CCK (http://drupal.org/project/cck)
- Adds fields to content types
- Views (http://drupal.org/project/views)
- Creates lists of content and users
- FileField (http://drupal.org/project/filefield)
- Adds a field for uploading files to content types
If you would like to participate in the hands-on exercises in this chapter, you should install Drupal using the Job Posting installation profile from the book’s sample code. Doing this will create the example website on your web server. The website will look as pictured in and at http://jobs.usingdrupal.com. For more information on using the book’s installation profiles, see the .Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- Inhaltsvorschau
Figure : The Epic University site after installationSeveral students on work-study at Epic University have been tasked with building a job posting website for their school. The university needs to have the site built in a short amount of time on their internal servers. Because students are building the site, it’s also obviously on a tight budget. Because of its flexible node system, user management, and low cost, the students chose to download Drupal and get started building a site.The Human Resources department requires that university faculty be able to post job openings, which include a description, department, contact person, and salary information. Users should be able to sign into the site and view both lists of all available openings and lists of openings within a single specific department. Additionally, users should be able to apply for a specific position, and to view a record of all positions to which they’ve applied.Drupal core provides this site with a good starting point. It provides the needed user authentication and allows the creation of several different types of content, such as “job” and “application” types. Drupal’s out-of-box functionality gives each one of these new types only a “Title” and “Body” field. We’ll need quite a few more fields so that users can enter data into different fields, and so that we can pull out information from certain fields to make listings of content.Custom input forms
At the heart of the requirements for this website, textual data will need to be inserted through a variety of forms. CCK provides the means to enter data into the site. CCK can provide several different kinds of fields needed, like a drop-down select list for the university department, or simple text fields for phone numbers and addresses.Listings
Besides entering data into the website, job applicants and employers will want to view lists of potential jobs and applicants. For nearly any purpose of displaying content, the Views module can provide a listing of content in a variety of ways: a table, a list of full nodes or teasers, an RSS feed, a list of individual fields, and more. We’ll build all the necessary lists for this chapter as views, including special views that can take a user ID or department and filter down to include only relevant content.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: CCK
- InhaltsvorschauCCK is an extremely flexible framework for creating forms to enter content. Although the Drupal core provides the ability to create different content types (such as a Job Opening or Application), it does not yet provide a mechanism for adding fields to the newly created types. Until CCK fields become integrated into Drupal core (which is expected in future releases), installing CCK should be the first step in nearly any Drupal website.Upon installing a new copy of Drupal, there are two content types provided: Story and Page. Both are fundamentally the same thing—a form that contains a Title field and a Body field. Any additional content types that are created will also contain a Title field and (optionally) a Body field; it takes an add-on module like CCK to add additional fields to a content type. depicts the Story content type as it appears prior to adding fields with CCK.
Figure : The Story content form, as presented to an authenticated user on a new Drupal siteAfter enabling the CCK module, any number of custom fields may be added to any content type. Combined with Drupal core’s ability to create any number of custom content types, CCK lets you create any number of completely customized forms for adding content. shows the same form after adding a few custom fields, such as an additional text field, an image field, and a set of radio buttons.
Figure : The Story content type form, after adding custom fieldsAfter adding the fields, CCK can automatically handle saving information to the database, and after data is submitted, presenting this information in a variety of ways.Functionally, CCK is set up into two end-user pieces. The first of these are fields, which allow a user to save data into your site. Fields represent the type of data that needs to be saved, such as integer, decimal, or text. When choosing a field to add to a content type, the first decision you need to make is what kind of data is being stored “behind the scenes” in the form. Will the information entered into the form be something basic like text or numbers, or something more special like a relationship to another node or user? The field types included in CCK “core” are displayed in . Other modules, such as Fivestar (Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: CCK
- InhaltsvorschauTo get started with our Job Posting website, let’s think about the different content types needed to build all the functionality that we require. The site requires two different types:
- Job Type
- Description and details of a particular job opening.
- Job Application Type
- An application ties together an individual and a particular job.
We will need to relate job applications back to the appropriate job openings, as well as relate jobs back to the appropriate contact person. The node reference and user reference fields mentioned earlier in the chapter will be an essential tool.
Figure : A mock-up of the forms required for the job website
Figure : Enabling CCK modulesWhen building out content types in Drupal, it’s best to start with a mental picture of what the form looks like that you’re trying to build. shows a sketch of both the job and job application forms that we’re shooting for.- To enable CCK, go to Administer→Site building→Modules (admin/build/modules). Enabling CCK involves two parts: enabling the Content module, which is the “core” of CCK, and enabling one or more “field” or “widget” modules.The FileField module is a separate module that is not included as part of the default CCK installation. It may be downloaded from http://drupal.org/project/filefield, and is also included in the book’s source code.
- Enable the following modules and click “Save configuration.” After the modules are enabled the page should look like :
- CCK package:
- Content
- FileField
- Node Reference
- Number
- Option Widgets
- Text
- User Reference
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Job Content Type
- InhaltsvorschauIn order to build this site, we’ll need to go beyond the default Page and Story content types offered by Drupal core. This section will cover how to add your own custom content type, as well as add custom fields to it with CCK.The Job content type will contain all the information we need to store about a particular position that’s available at Epic University. It will need the following fields:
- Job Title (the normal node title)
- Description (the normal node body)
- Department (a text select field)
- Contact (a user reference field)
- Salary (an integer field)
Let’s walk through the steps to create this new content type:- Start by visiting the main content type settings page under Administer→Content management→Content types (admin/content/types). Click the “Add content type” tab at the top of the page (admin/content/types/add).
- Using the settings indicated in , create a new content type called Job. We repurpose the Title and Body fields for Job title and Description, respectively, simply by changing their labels. Be sure to expand the fieldset for “Submission form settings” to enter the title and body field labels. When completed, your screen should look similar to .
Table : Settings for the Job content type FieldValueIdentificationNameJobTypejobDescriptionA currently available job positionSubmission form settingsTitle field labelJob titleBody field labelDescription
Figure : Adding a new “Job” content type- After submitting the form with the “Save content type” button, the new content type will be created. Click the “manage fields” link for the Job content type (admin/content/node-type/job/fields) to add our first custom field.
- Use the settings from and pictured in to complete the New field form to add a new select list for the Department field. Choose Text as the field type, as the field will be used to store text values. Once you’ve selected the field type, the widget type selection will appear.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Customizing Field Display
- InhaltsvorschauFor usability, it’s often important to display forms and page contents in a specific order, and to add formatting so that it’s more clear what data is being presented. The following take you through some minor customizations to the way fields are displayed:Before testing our form out, we should reorder the fields on the form so that they make more logical sense. Click through Administer→Content management→Content types and click “manage fields” next to the Job type (admin/content/node-type/job/fields), where you can arrange the fields however you like. Drag the handle on the left side of each row and arrange the table so that it is in the order shown in , and click the Save button when finished:
- Job title
- Department
- Description
- Salary
- Contact
- Menu settings
Figure : Field order for the Job content typeThe Job content type is now nearly complete. Let’s take a look at what our form currently looks like. Log in as editor, password oreilly, and create a new Job piece of content at Create content→Job (node/add/job). The form should look similar to (as admin user, you’ll see several more options that are hidden from other users). Click Save when you’re finished filling in the fields.
Figure : The Job form as seen by a user in the “editor” roleTaking a look at content after it’s created, we’ll see that it’s not entirely pretty. shows the default output of our Job type when viewing the content. The labels are included above each of the fields, making the page longer than it needs to be, and the salary could really use a comma.
Figure : Default output of the Job content typeFortunately, CCK provides several different ways of changing the default content, the easiest of which is CCK Formatters. Any module in Drupal is allowed to create for displaying various fields, and CCK provides a few that will work in most situations. Follow these steps to change the display of the Job content to be a bit more appealing:Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Job Application Type
- InhaltsvorschauNow that the university is able to create job positions, it would be helpful if users could submit résumés to the positions in which they’re interested. We’ll create another content type called “Job Application” or just “application” for short, using the following fields:
- Title (the normal node title)
- Introductory message (the normal node body)
- Job (node reference field)
- Résumé (file field)
- Return to the main content type settings page under Administer→Content management→Content types (admin/content/types). Add another content type by clicking on the “Add content type” tab at the top of the page.
- On the “Add content type” page, fill in the form with the values from . Again, we’ll easily create the first two fields (Title and Introductory message) by reusing the Title and Body fields provided by Drupal core.
Table : Settings for the Job content type FieldValueIdentificationNameJob ApplicationTypeapplicationDescriptionAn application for a job positionSubmission form settingsTitle field labelTitleBody field labelIntroductory message
- After submitting the form with the “Save content type” button, the new content type will be created. Click the “manage fields” link for the “Job application” type (admin/content/node-type/application/fields). Use the settings from to add a node reference field for the job type. This will connect a particular “Job application” node with the Job node.
Table : Add field settings for Job node reference FieldValueLabelJobField namejobSelect a field typeNode referenceSelect a widgetSelect list
- Click Continue and configure the Job node reference field with the values from .
Table : Settings for the Job node reference field
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Views Module
- InhaltsvorschauThe Views module provides listings of data on your site: users, comments, nodes, and more. Any listing of data provided by the Views module is called a view, which we’ll always refer to in all lowercase to distinguish it from the Views module, which is . shows examples of some of the listings that can be built with the Views module.
Figure : Examples of views created by the Views moduleCreating a basic view entails selecting the fields you would like displayed (node title, author name, and images, etc.), how you would like that list to be filtered (only display “story” node types that are published), how you would like the listing to be sorted (newest stories on top), and what you would like the list to look like when it’s displayed (a block showing a bulleted list of headlines).In more technical terms, Views is a visual SQL query builder. When you build a view, you are essentially constructing a query that Views will pull from your site database. The Views module has significant advantages over a handcoded query. Some examples:- You don’t have to write any code just to make a listing of content.
- Modules will tell Views about their fields; you don’t need to know anything about the underlying database structure, and you are insulated in case this structure should change behind the scenes between module updates.
- The same view can be used in several places on the site, as both blocks and pages.
- Results can be split into multiple-page listings, use sortable table columns, AJAX pagers, or filtering drop-downs to allow visitors to “drill down” to the content they want.
More than anything else, Views can significantly speed up the development of your site, without your having to learn module development or a single line of PHP. Views can form the backbone of outputting content on your site.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: The Views Module
- InhaltsvorschauThe requirements of our site include two particular views. One view is frontend-facing, showing all the available jobs to users of the site. Faculty users (more specifically, users in the “editor” role) will use the second view to review the list of applicants who have applied to various jobs.The first step to using the Views module is to enable it. The Views module has two parts: the Views module itself, which handles the low-level “plumbing,” and the Views UI module, which presents the screens used to configure them. Additionally, the Advanced Help module is an optional module that provides useful inline help for modules such as Views.
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Other package
- Advanced Help
- Views package
- Views
- Views UI
- Configure the module permissions at Administer→User management→Permissions (admin/user/permissions), using the values listed in . As administrators will be the only people configuring the Views module, the Advanced Help features need to be enabled for them only.
Table : Permissions for the Views module Permissionanonymous userauthenticated usereditorsite administratoradvanced_help moduleview advanced help indexCheckedview advanced help pop-upCheckedview advanced help topicCheckedviews moduleadminister viewsCheckedviews_ui moduleaccess all viewsCheckedBe very cautious with the “access all views” permission; users with this permission will bypass any access restrictions you place on views, so all views are visible.
The “jobs” view will provide a listing of jobs at Epic University, categorized by department. The completed view will be similar to the one pictured in .
Figure : A sample page from the jobs view, listing jobs in the Administration departmentEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauThe basic job website that we’ve built only touches on the surface of the capability of CCK and Views. There are a lot of possibilities for extending the functionality of this job site by adding more fields to both the Job and Job Application content types. Here are a few modules that could be used to extend the abilities of CCK:
- Automatic Node Titles, http://drupal.org/project/auto_nodetitle)
- This module provides support for creating title templates for nodes. For example, rather than having users manually enter a title for their applications (which may result in nonsensical things such as “Hire me!”), this module could ensure that all application titles follow a standard format automatically, such as [author-name] – [job-title].
- Custom Links, http://drupal.org/project/custom_links
- This handy module can be used to add your own links to any node in addition to the usual suspects, such as “Add new comment.” We could use this to add a link for users to apply for a job directly from the job post itself, so users did not need to select it from a drop-down box from the application form.
- Content Permissions (included with CCK)
- If you need to protect certain private application information from displaying to unprivileged users, the Content Permissions module can hide fields depending on the viewing user’s role. As it’s included with CCK, no additional download is .
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauThis chapter taught you how to use two of Drupal’s fundamental “building block” modules: CCK and Views. These modules constitute the cornerstone of Drupal’s power and are used extensively throughout the rest of the book. CCK is used to model your website’s content by adding additional fields to hold different properties, and Views is used to display lists of your website’s data.Besides the basic features of these modules, this chapter also introduced you to the methodology for Drupal site building. Rather than installing monolithic packages, in Drupal each module provides specific functionality, and works together with other modules to enhance their functionality. As we created fields for our different content types, CCK was working together with the core Node module. While making listings of content, Views retrieved information provided by both core modules and CCK. This sort of cooperation between modules serves as the foundation for the rest of the book, as more modules join the party and give new shape to our sites.Here are the modules that we referenced in this chapter:
- Address module: http://drupal.org/project/address
- Automatic Nodetitle module: http://drupal.org/project/auto_nodetitle
- Content Construction Kit (CCK) package: http://drupal.org/project/cck
- Custom Links module: http://drupal.org/project/custom_links
- FileField module: http://drupal.org/project/filefield
- Link module: http://drupal.org/project/link
- Token module: http://drupal.org/project/token
- Views module: http://drupal.org/project/views
These are some other resources that we referenced and community resources for learning more about the new concepts introduced in this chapter:- CCK Developers Drupal group: http://groups.drupal.org/cck
- CCK Field modules: http://drupal.org/project/Modules/category/88
- Views Developers Drupal group: http://groups.drupal.org/views-developers
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 4: Product Reviews
- InhaltsvorschauWith more and more options for shoppers arriving on the Internet every day, finding the right products can be a challenge. Special interest websites that feature specific kinds of products and reviews by dedicated hobbyists are a popular way to help consumers sort through all of the options and find the right products. In this chapter, we’re going to use a handful of Drupal modules to build a product review website that lets community members give their opinions on every product that’s featured.This chapter introduces the following modules:
- Amazon (http://drupal.org/project/amazon)
- Gathers product information from Amazon.com
- Voting API (http://drupal.org/project/votingapi)
- Provides a framework for standardizing voting data
- Fivestar (http://drupal.org/project/fivestar)
- Allows rating of content
- Search (core)
- Indexes content and allows searching within a site
- CSS Injector (http://drupal.org/project/css_injector)
- Allows administrators to easily add CSS styling to the site
If you would like to participate in the hands-on exercises in this chapter, install Drupal using the Reviews installation profile from the book’s sample code. This will create the example website on your web server. The completed website will look as pictured in and found at http://reviews.usingdrupal.com. For more information on using the book’s sample code, see the .
Figure : The completed Super Duper Chefs websiteBob and Sarah are coworkers and food lovers who’ve both built up impressive kitchens full of gadgets, pots and pans, and other cooking tools. Supporting a culinary habit can be expensive, though, and they usually turn to fellow foodies for advice before purchasing new gear. They’ve decided to set up Super Duper Chefs, a website where they and their friends can write recommendations about the cooking equipment they use, share tips, and brag about their latest culinary achievements. They’d like it to be the kind of site they wanted when they were getting started: a fun place that highlights the most useful products and advice.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- InhaltsvorschauBob and Sarah are coworkers and food lovers who’ve both built up impressive kitchens full of gadgets, pots and pans, and other cooking tools. Supporting a culinary habit can be expensive, though, and they usually turn to fellow foodies for advice before purchasing new gear. They’ve decided to set up Super Duper Chefs, a website where they and their friends can write recommendations about the cooking equipment they use, share tips, and brag about their latest culinary achievements. They’d like it to be the kind of site they wanted when they were getting started: a fun place that highlights the most useful products and advice.After talking things over with their friends, Bob and Sarah think they have a handle on what the site should offer. The most important feature is that kitchen products reviewed by the site’s official contributors should be listed with ratings and quick summaries of their best and worst features. Each review should also provide up-to-date pricing information. In addition to the official reviews, visitors to the site should be able to offer their opinions on the products and compare the official ratings with the opinions of other visitors who’ve read the reviews. Everyone that uses the site should also be able to search for reviews that match certain criteria. For example, it should be easy to find reviews of products by a particular manufacturer, or products that mention waffles.The next step is figuring out how to translate that set of features into a shopping list of Drupal functionality. Bob and Sarah are fortunate: the core Drupal software can provide most of what they’re looking for without any additions. We’ll set up special permissions for contributors, and use Drupal’s administrative tools to create a custom Product Review content type. Those Product Reviews will be the meat of the site’s content.We’ll use the CCK module to add custom fields to the Product Review content type for the various bits of information we want to record. We’ll also use the Views module to build a listing page of products for quick scanning. Three requirements for Bob and Sarah’s website, though, will require functionality that we haven’t seen yet: importing product information from another website, allowing users to rate and review content, and building a custom search page.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- First Steps: Basic Product Reviews
- InhaltsvorschauBefore we get started, log in to the site with the username admin and password oreilly if you are using the installation profile. We’ll get started with a few things that we are going to need.One thing we will need is a new content type for the product reviews. Based on the Super Duper Chefs requirements, we’ll need the following for each review:
- A Pros field and a Cons field to list quick summaries of each product’s strengths and weaknesses
- An Amazon Product field to hold detailed product information
- A Rating field, so that visitors can quickly find the cream of the crop
- A Field Group that combines the rating, as well as the pros and cons, for a more attractive presentation
- Comments so that visitors can weigh in with their own opinions
We’ll start by creating the base content type and adding the simplest pieces: the basic text fields needed for the Pros and Cons, grouping those fields together, and allowing comments:- First, go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- CCK package
- Content
- Fieldgroup
- Text
- Next, go to Administer→Content management→Content types (admin/content/types) and add a new content type called “Product review,” using the settings indicated in .
Table : Settings for the Product Review content type SettingValueIdentificationNameProduct reviewTypereviewDescriptionA featured product review by a contributing editorSubmission form settingsTitle field labelHeadlineBody field labelReviewComment settingsDefault comment settingRead/WriteComment subject fieldDisabledLocation of comment submission formDisplay below post or comments
- Save the changes you’ve made by clicking the “Save content type” button and you’ll be returned to the listing of available content types. Click the “manage fields” link (admin/content/node-type/review/fields) for our new Product review content type to begin setting up the custom fields.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Amazon Module
- InhaltsvorschauAmazon.com is one of a large number of web-based businesses that have opened up their product information databases for other sites to access. In the case of Super Duper Chefs, we want to retrieve useful data like product photos, pricing, and manufacturer information for display on our own website. The Amazon module for Drupal allows us to do just that.The Amazon module is actually an entire collection of modules, each with its own purpose:
- The core Amazon API module handles communication with the Amazon.com website and ensures that pricing information on products stays up-to-date. All of the other modules included in the package require this one.
- The Amazon Media module stores extra information about certain types of products. For example, it’s responsible for storing and displaying the MPAA rating for movies and the console that video games run on.
- The Amazon Search module adds the ability to search for Amazon.com products from Drupal’s default Search page.
- The Amazon Field module allows administrators to add a field to any content type that stores an Amazon product ID, and displays a photo of the product straight from Amazon.com. This module is the one that we’ll be using to enhance our Product Review content type.
- The Amazon Filter module allows writers to insert product images and information into any piece of content using the
[amazon]tag. It’s useful for bloggers or writers who want to link to products occasionally but don’t need the structure of an explicit field just for product links.
The Amazon module doesn’t require much configuration, but there are several important settings that most site administrators will want to change on its configuration page, at Administer→Site configuration→Amazon API (admin/settings/amazon) and pictured in .
Figure : The Amazon module’s settings pageBecause each country that Amazon operates in has a separate database of products, prices, and availability information, you’ll want to choose the Locale that your website’s users reside in. This setting will determine which Amazon website (Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Adding an Amazon Field
- InhaltsvorschauIn the previous section of this chapter, we set up a content type for our product reviews. Now, we’re ready to add an additional field to store a link to the product on .com. We need to do a few things to get set up before we add the field to our content type:
- First, go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Amazon package
- Amazon API
- Amazon Field
- Next, go to Administer→Site configuration→Amazon API (admin/settings/amazon). Select your locale and add your Amazon Associate ID, if you have one. If you are in the United States and do not have an Amazon Associate ID, you can use the default settings.
Having set up the Amazon module, we’re ready to continue customizing the Product Review content type:- Go to Administer→Content management→Content types (admin/content/types) and click the “manage fields” link (admin/content/node-type/review/fields) for the Product Review content type and create a new field using the settings indicated in .
Table : Settings for the Product ID field SettingValueLabelAmazon Product IDNameproduct_idField typeAmazon itemWidgetText field
- Click the Save button to create the field, and you’ll be taken to the next screen to fill out the field settings as shown in .
Table : Settings for the Product ID field SettingValueProduct review settingsHelp textEnter the Amazon product ID of the item you’re reviewing.Global settingsRequiredChecked
- Click the “Save field settings” button to complete the process, and you’ll be returned to the “Manage fields” page for the Product review content type.
- On the “Manage fields” page (admin/content/node-type/review/fields), rearrange the new Amazon field so that it is listed under the Pros and Cons fields, like so:
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Voting API and Fivestar
- InhaltsvorschauGiving visitors a chance to evaluate and rate content is an extremely common pattern on content-rich websites. In addition to giving visitors a way to jump to the best content, it can give you—the site’s administrator—a way to determine what content on your site is most effective.Almost all rating and evaluation modules for Drupal rely on a shared module called Voting API. Though it offers no features for your site on its own, it gives developers a set of tools for building rating systems and provides a common format for storing votes and calculating the results. This allows developers to focus on what makes their work unique (presenting vote results in a novel way, for example) while Voting API handles the grunt work.One of the other advantages of this system is that modules based on Voting API can often share the same data. For example, the jRating (http://drupal.org/project/jrating), Criteria Rating (http://drupal.org/project/criteria_rating), and Fivestar (http://drupal.org/project/fivestar) modules all offer slightly different features, but they accomplish the same thing: rating content on a scale, and displaying the current average as an Amazon-style star rating. Although they look different and give administrators different options for presenting and using the results of the voting, they can be used . Votes cast by one of these modules can be used by any of the others, as they’re stored and maintained by the shared Voting API.The Fivestar module offers numerous configuration options, from the style and color of stars that it uses to display ratings to how results are presented when visitors look at a new piece of content. shows the Fivestar module’s selection of rating widgets. The widget visitors use to rate each post can be displayed in the post itself, in a floating sidebar block, or even in the commenting form when visitors submit a reply.
Figure : The Fivestar module’s selection of rating widgetsDespite what its name suggests, Fivestar can display any number of stars: 10 stars, 3 stars—even 1-star scales can be used. In addition, it provides a custom field type for the CCK module: a simple numeric field on any piece of content can be displayed using Fivestar’s custom widget, separate from the ratings cast with Voting API.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Adding Ratings
- InhaltsvorschauFor the Super Duper Chefs site, we’ll be using both of Fivestar module’s unique features: adding a static Rating field to the Review content type, and attaching a voting widget to the comment form on each review. That approach will keep the official rating on each review separate from the reader ratings.First, go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Voting package
- Fivestar
- Fivestar Comments
- Voting API
Go to Administer→Content management→Content types (admin/content/types), click the “manage fields” link for the Product Review content type (admin/content/node-type/review/fields), and create a new field using the settings indicated in .Table : Creating the “Rating” field SettingValueLabelRatingNameratingField typeFivestar RatingWidgetStarsClick the Save button to create the field, and you’ll be taken to the detailed settings page. Choose the settings indicated in , and click “Save field settings” to add the field. Because these are editorial reviews, it doesn’t make sense for users to be able to remove their vote, so we’re going to remove the ability to do so. We’ll also add this field to the Summary group so that it’s displayed along with the pros and cons.Table : Detailed settings for the “Rating” field SettingValueProduct review settingsAllow user to clear viewUncheckedGlobal settingsRequiredCheckedNumber of Options5When you return to the “Manage fields” tab (admin/content/node-type/review/fields), rearrange the new Rating field above the Pros and Cons inside the Summary group. After you click the Save button, the list should look like this:- Headline
- Menu settings
- Summary
- Rating
- Pros
- Cons
- Amazon product ID
- Review
Click the “edit” tab for the Product review content type (admin/content/node-type/review) and open the “Fivestar ratings” section of the page. Once you’ve checked “Enable Fivestar rating” for the content type, a preview of the rating widget based on the settings you’ve selected will appear on the page. Feel free to experiment with different settings: the Fivestar module will offer a preview that reflects your choices. Fill out the settings with the values in , as shown in . This setup will show the user’s own vote if available; otherwise, it shows the average vote across all users.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Building a Product List
- InhaltsvorschauNow that we have a few products, we really ought to add a listing page that lets visitors look over all of the products that have been reviewed, comparing official ratings with visitor ratings and sorting by various criteria, as pictured in . This page will be simple to build with the Views module.
Figure : Product finder view- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Other package
- Advanced help
- Views package
- Views
- Views UI
- Go to Administer→Site building→Views and click on the Add tab (admin/build/views/add) and fill in the new view settings using .
Table : Settings for creating the Products view View settingValueView nameproductsView descriptionList of reviewed productsView tagproductsView typeNode
- After clicking the Next button, configure the “Basic settings” section of the view, using .
Table : Basic settings for the Product finder view Defaults: Basic settingsValueTitleProduct FinderStyleTable
- After setting those Basic settings, you will see a message that states “You need at least one field before you can configure your table settings.” We are going to go ahead and do that in a minute, but first we need to create a relationship for our fields so that we can use Amazon-specific fields in the view and display the average rating given to each product by visitors to the site.Click the
+(plus) icon in the Relationships section and check both the “Content: Amazon item: Amazon product ID (field_product_id)” and “Node: Voting results relationships.” Click the Add button to add the relationship and then fill out the settings in when prompted. Press Update after each form is .Table : Voting Results relationship settings for the Product finder view
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: The Search Module
- InhaltsvorschauDrupal’s built-in Search module offers powerful, flexible searching features and intelligent ranking of results. Behind the scenes, it’s silently building an index of all the words used in the site’s content. When users search for a phrase on the site, content is ranked using customizable rules and displayed in order of relevance. On any Drupal site, you can refine these rules by going to Administer→Site Configuration→Search Settings (admin/settings/search) and changing the Content Ranking weights, pictured in .
Figure : The Search module’s configuration pageThe Search module also offers more detailed options for sites with large amounts of content. The Advanced Search screen, pictured in , allows users to choose exactly what content they want to search, filtering based on content type, free tagging terms, and other criteria.
Figure : The Advanced Search page in actionThe indexing process used by Drupal’s Search module only works when the “cron” utility has been properly configured. cron is a utility used to run various commands at scheduled intervals on your web server. It is responsible for performing maintenance tasks on a Drupal site, such as clearing old log entries, as well as scheduling bulk email and other tasks that happen with regular frequency.Each time cron runs, Drupal will catalog some of the site’s content; by default, it indexes 200 posts each time. If your site has a large number of posts already, the speed of the indexing will depend on how frequently cron is configured to run on your server.If you’re not sure whether cron has been set up, or if you’re running on your local computer to test the site out, you can tell Drupal to perform its cron tasks by visiting Administer→Reports→Status report (admin/logs/status) and clicking the “run cron manually” link. For more information on setting up cron for your site, see http://drupal.org/cron.An alternative to setting up cron is to install the Poormanscron module (Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Make the Product List Searchable
- InhaltsvorschauTo transform the Product finder page into a searchable index, we’ll be adding two new filters to the view: one that restricts the results by manufacturer and another that restricts results to reviews that mention specific words.Normally, these filters are locked in place and can’t be modified, except by the site’s administrator. We need users to enter their own criteria, however. Fortunately, Views allows us to “expose” any of its normal filters. Doing so adds a small form to the heading of the view’s display page. Visitors to the site can use it to change how Views filters its results, turning any view into a simple search tool, as pictured in .
Figure : Searchable Product Listing viewHere are the steps to get your searchable list:- Enable searching on the site: go to Administer→Site building→Modules (admin/build/modules) and enable the Core: Search module.
- Go to Administer→Site building→Views (admin/build/views) and click the Edit link for our Product finder view.
- Click the
+(plus) icon in the Filters section to check the Amazon: Manufacturer and Search: Search Terms filters. - On the settings form for each of the filters, click the Expose button, which will present the filter as a form field that a site visitor can interact with. Configure the Exposed Filter settings for each filter using the values in . As usual, click Update to move between the configuration forms.
Table : Settings for the Search Terms filter Defaults: Configure filter settingValueAmazon: ManufacturerOperator: ContainsCase sensitive: UncheckedLabel: Manufacturer:Search: Search TermsOn Empty Input: Show AllLabel: Keywords:
- Click the ↑↓ (rearrange) icon on the Filters section and move Search: Search Terms above Amazon: Manufacturer so that its box will appear first.
- Save the view, which should now look like .
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: CSS Injector
- InhaltsvorschauDrupal’s theming system, which is introduced in , gives designers complete control over how a site’s content is rendered for a web browser, and custom themes (like the Nitobe theme that we’re using for the Super Duper Chefs site) can give any site a distinctive look. But sometimes it’s useful to make minor tweaks to a site’s appearance using nothing but CSS rules. They allow designers to tweak font sizes, colors, and so on without altering the underlying HTML that defines the site’s structure.The CSS Injector module (http://drupal.org/project/css_injector) gives administrators the ability to add those snippets in an administration screen within your site, without having to make changes to the current theme’s files. This feature can be useful when a new version of your site’s theme is released on Drupal.org—if you change the theme to add your own CSS, it’s easy to lose those modifications when you download the new version. Keeping them in CSS Injector will preserve them even if you change themes.CSS Injector offers a number of advanced options, including the ability to add the CSS rules conditionally on certain pages. If your CSS tweaks only apply to the front page, for example, you can ensure that it won’t add the unnecessary rules to the entire site. You can also specify a media type for your CSS, which makes it possible to add styling information that applies only when a page is being printed. Finally, each rule can use the Preprocess CSS checkbox to control whether Drupal should merge its rules with the current theme’s CSS. In most cases, this step saves time, because a visitor’s web browser makes only a single trip to your site’s web server to download all the stylesheets. If you’re adding extremely large amounts of CSS code that only apply to one or two pages, it can be more efficient to keep that code separate by turning preprocessing off. Otherwise, leave it enabled.If you’re mystified by CSS, http://w3schools.com/css/default.asp provides interactive work areas for learning all types of web technologies, including CSS. It’s a great resource to keep bookmarked.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Hands-On: Polishing the Presentation
- InhaltsvorschauIn this section, we’ll do some final tweaking to make the review display look nice and tidy, as pictured in .
Figure : Completed review displayAlthough our Product Reviews content type has all of its data in order, and our product listing pages are looking great, the individual reviews still look a bit untidy. Fortunately, we can use the CCK module’s display settings to tweak how each type of field is displayed in the reviews.Go to Administer→Content management→Content types (admin/content/node-type), click the “edit” link, and then click the “Display fields” tab (admin/content/node-type/review/display). Fill out the fields using the settings in , which will help streamline the display of review information. Click the Save button when you are done.Table : Display settings for the Product Review content type FieldLabelTeaserFullSummary<Hidden>SimpleSimpleRatingInlineAs StarsAs StarsProsInlineDefaultDefaultConsInlineDefaultDefaultAmazon Product ID<Hidden>Small image and full infoSmall image and full infoChanging the CCK Display settings for our reviews cleans things up quite a bit, but the Summary information still seems awkward. In , we cover some of the basics of theming the HTML that Drupal outputs, but for now we can improve things quite a bit by adding some CSS rules using CSS Injector. We’ll use it to reduce the width of the Summary box and float it to the side of each review, turning it into a floating sidebar rather than a header at the top of each review. Here’s how:- Go to Administer→Site building→Modules (admin/build/modules) and enable the Other: CSS Injector module.
- Go to Administer→Site configuration→CSS Injector (admin/settings/css_injector) and click the “Create a new rule” link to add a new CSS rule.
- Name the rule “Floating Amazon fields,” and enter the following text into the CSS code field. You can see the completed form in .
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauCongratulations! All of the major features for the site are in place. If you’re interested in experimenting further, there are quite a few opportunities for additional enhancements using other Drupal modules.
- Notifications (http://drupal.org/project/notifications)
- This module gives visitors to the site the ability to request email notifications each time a new review is posted. It also allows official site contributors to receive email when visitors post comments to their reviews.
- AdSense (http://drupal.org/project/adsense)
- This module allows Bob and Sarah to place ads in the sidebar to offset the costs of hosting the site.
- Blog (core)
- This module allows the site’s writers to each have their own blog on which to discuss their cooking tips, latest recipes, and other culinary exploits, even when they’re not reviewing products.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauAfter all that work, where have we arrived? We’ve hit all of the major pieces of functionality that Bob and Sarah wanted. Using CCK, Amazon, and Fivestar, writers can post their reviews of cool kitchen products to the site. With Fivestar and Voting API, visitors to the site can offer their opinions on those same products and participate in the reviewing process. And with Views’ Search module integration, it’s easy for them to find the exact products that they’re interested in. Finally, the CSS Injector module allowed us to sprinkle on those finishing touches that make the site really shine.Here are the modules that we referenced in this chapter:
- AdSense: http://drupal.org/project/adsense
- Amazon: http://drupal.org/project/amazon
- CSS Injector: http://drupal.org/project/css_injector
- Fivestar: http://drupal.org/project/fivestar
- Poormanscron: http://drupal.org/project/poormanscron
- Subscriptions: http://drupal.org/project/subscriptions
- Voting API: http://drupal.org/project/votingapi
Here are some other resources we referenced:- Amazon Associates program: http://affiliate-program.amazon.com/
- Configuring cron jobs: http://drupal.org/cron
- Evaluation and rating modules: http://drupal.org/project/Modules/category/60
- Third-party integration modules: http://drupal.org/project/modules/category/52
- Voting Systems Drupal group: http://groups.drupal.org/voting-systems
- W3Schools CSS Tutorial: http://w3schools.com/css/default.asp
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 5: Wiki
- InhaltsvorschauThe collaborative nature of wikis has given rise to new and exciting methods of online knowledge management. Wikipedia, the most famous example of a wiki, is an online encyclopedia consisting of millions of articles, constantly written and updated by thousands of volunteers from around the world. By combining a few add-on modules, can also harness this sort of power and combine it with the other great features that Drupal already provides.But what is a wiki? A wiki is a collection of web pages that visitors may contribute to by adding and editing content through their browser. Wikis keep track of changes made and have the ability to revert to earlier versions when needed. Wikis often use a simplified text markup to allow quick and easy formatting. A key technical feature is the ability to create links to pages that don’t yet exist, allowing the structure of the site to grow organically. What all of that means is that a wiki is a great tool for a group to use to collaborate when writing documents. Many people can work together on a “living” document that gets changed and updated as needed.In this chapter, we will build a wiki with Drupal and cover some really cool things that Drupal can do—wiki or not.This chapter introduces the following modules:
- Freelinking (http://drupal.org/project/freelinking)
- Provides the ability to easily link between pages
- Markdown filter (http://drupal.org/project/markdown)
- Provides an easy, human-readable way to enter HTML formatting
- Diff (http://drupal.org/project/diff)
- Shows color-coded list of changes between two revisions of content
- Pathauto (http://drupal.org/project/pathauto)
- Automatically creates clean, search-engine-friendly URLs
- Token (http://drupal.org/project/token)
- A utility module to provide variables that are later replaced with dynamic bits, such as [user-name]
If you would like to participate in the hands-on exercises in this chapter, install Drupal using the Wiki installation profile from the book’s sample code, which will create the example website on your web server. The completed website will look as pictured in and atEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- InhaltsvorschauThe Berchem University Student Government Association (SGA) needs an internal site that all of its members can use to collaborate on the SGA’s business, which is accessible only to members of the SGA. Because they are all very busy students on different schedules, it is hard to find time to actually meet in person to get work done. They need a place to create and update information for such things as internal policies and procedures, meeting notes, and event planning. The SGA is formed by a number of groups around the campus and they would like everyone to be able to use the site to collaborate, but they also have some specific information to be made available that should be editable only by the executive officers.Most of the members do not know HTML, but need to be able to add basic formatting to their text and easily create links to both existing pages and pages that don’t exist yet. They also need to be able to see changes that are made to the pages over time and revert back to earlier versions. They would also like to make the URLs be easily remembered words rather than random numbers (for example, http://example.com/annual-blood-drive as opposed to http://example.com/node/123).Finally, they need a way to track the activity of the wiki, which will entail two listing pages: one to show newly added pages, and another to show pages that were recently edited.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Implementation Notes
- InhaltsvorschauIn the following subsections, we’ll discuss the modules used and their implementation.There is a long list of modules to help us satisfy the requirements for this site. When looking for wiki solutions, the obvious place to start looking would be wiki modules. There are three modules with “wiki” in their names, Wiki (http://drupal.org/project/wiki), Liquid Wiki (http://drupal.org/project/liquid), and Wikitools (http://drupal.org/project/wikitools). Wiki was developed as a means to centralize the various wiki solutions in Drupal in a single package, but has been abandoned since 2006 and therefore is of no interest. Both Liquid Wiki and Wikitools are not “complete” wiki packages. They both group together some common needs in wikis, but rely on other modules for much functionality. Unfortunately, at the time of this writing, it appears that the Liquid Wiki module is also not being maintained, as there are no official releases and no development has occurred since February 2007. That leaves us with Wikitools as the only viable one in the group.At the time of this book’s writing, the Wikitools module was under development and was not yet ready for production use. It adds some nice features, like automatically redirecting links if a wiki post path changes and protection against moving pages (regular users can’t retitle a wiki post, which would change the post’s path). These are nice but certainly not needed in our scenario. Check back for updates on the status of the module; as with all other tools in the Drupal world, things can evolve quickly if enough interest is focused on them.However, we can build a wiki without any of those modules, which is what we’ll be doing in this chapter. There are many modules that will give us the functionality we need, just not under the banner of “a wiki module.” We can use all the tools that Drupal provides, not just the obvious or obviously named ones. Drupal core already has many “wiki” features built in, so we just need to provide a few extra touches to make our site like what people expect from a wiki.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Hands-On: First Steps
- InhaltsvorschauThis section will cover the foundation that is required in order to complete the hands-on exercises in the rest of the chapter.The first thing to do is make sure that we have the content types that we need for our site. The student government needs pages that are only editable by the moderators, as well as the main content that everyone will edit. To easily distinguish between these use cases and to control access, we’ll have two content types: Page and Wiki page.Drupal comes with two premade content types, Page and Story, as mentioned in , so Page content is already done for us. We don’t need the Story type, so instead of making a new content type for the wiki, we can edit the Story type to fit our needs.It is equally acceptable to delete the Story type and create a new Wiki page type. You can even keep the Story type, if you have a use for it.Go to Administer→Content management→Content types (admin/content/types) and you will see the existing page and story types. Click the “edit” link for the Story type and make the changes listed in , as seen in . Click the “Save content type” button to make your new content type.
Table : Settings for the Wiki content type FieldValueNameWiki pageTypewikiDescriptionA page that any authenticated user may edit and view changesWorkflow settings: Default optionsUncheck “Promoted to front page”; check “Create new revision.”
Figure : The settings for the new Wiki page content typeBecause all of the content on the site will be group content, we don’t want to have the default “submitted by username” information to display (inevitably, it won’t be just that person’s work). To remove that information from our new Wiki page content type, we need to take a short trip over to the theme section:- Go to Administer→Site building→Themes (admin/build/themes).
- Click the Configure tab (admin/build/themes/settings).
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Wiki Input Format
- InhaltsvorschauAs you may remember from , where input formats and filters were introduced, all of our content is passed through the filters included in the designated input format before being displayed. The users enter whatever crazy text they want on input, and then Drupal filters and modifies that text on output.One of the requirements for our site is to allow easy formatting and linking when writing content. The Markdown and Freelinking filters allow us to do just that. We are going to create a new input format for our wiki that uses a few core filters along with our contributed ones. The steps described in the following sections include:
- Configuring the filters
- Creating the wiki input format
- Setting up format permissions
- Adding content
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Input filters
- Markdown filter
- Other
- Freelinking
- Go to Administer→Site configuration→Freelinking settings (admin/settings/freelinking) and change the “Default for new content” to “Wiki page” so that links to nonexistent content will create new Wiki pages for us automatically. You can see these settings in . We are doing this because not all users have permission to create new Pages (as opposed to Wiki pages). (Note that the Markdown filter doesn’t require any additional configuration.)
- Click the “Save configuration” button.
- Go to Administer→User management→Permissions (admin/user/permissions) and set the permissions as shown in . Click the “Save permissions” button.
Table : Permissions for the Freelinking module Permission: freelinking moduleanonymous userauthenticated usereditorsite administratoraccess freelinking listchecked
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Pathauto
- InhaltsvorschauIn , you learned about the Drupal path and how to use clean URLs. One reason to use clean URLs is so that they don’t look so ugly. (To review, clean URLs remove the “?q=” from the URL.) That helps, but still leaves the URLs lacking a bit. Having a URL with “node/123” in it doesn’t really tell either humans or search engines much about the page itself. Isn’t it much better to instead have a URL with something like “about-us” in it? That is going to be much more memorable for a person, and the addition of pertinent keywords in the URL makes for better search engine optimization. So, even without clean URLs, you can still benefit from good pathnames.We’ll quickly review the core Path module that we mentioned in . When enabled, it will add a new fieldset to the node creation/editing form called “URL path settings,” as shown in . When you expand that fieldset, you will have a field in which to enter an alternative name for that node’s path (called a path alias). The name that you enter here will be used in place of the Drupal path, the part of the URL that comes after http://example.com/ (or http://example.com/?q= if you don’t have clean URLs ).
Figure : The Path module’s settings fieldset on a node edit formThis field is a huge help, but it can be somewhat tedious to enter all of those names by hand if you are creating a lot of content. Also, if you have many users making content, you need to make sure that they all understand this and use consistent naming throughout the site, which can be an administrative headache. Another limitation of the Path module is that we get that handy alias box only on nodes. What about things like user profiles or vocabulary paths?As often occurs in Drupal, contributed projects provide us with a module that deals with this issue. Enter the Pathauto module. As its name implies, it creates automatic path aliases for nodes, taxonomy, and user paths. Pathauto is dependent upon the core Path module and another module called Token, discussed in the sidebar.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Pathauto
- InhaltsvorschauTo get those handy human-readable URLs on our site, we are going to use the Pathauto module and, as you saw in the previous section, this relies on the Token module as well as the core Path module.Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Core—optional
- Path
- Other
- Pathauto
- Token
The Pathauto settings page is quite large and can be intimidating. Luckily, most of the defaults are what most sites will want to use anyway, so that makes our job with configuration a lot simpler than it may first appear.- Go to Administer→Site building→URL aliases (admin/build/path) and click the Automated alias settings tab (admin/build/path/pathauto). Add the following :
- Expand the “Node path settings” fieldset and in the “Pattern for all Wiki page paths,” enter “wiki/[title-raw]” as shown in .
- Expand the “User path settings” fieldset and change “users/[user-raw]” to “members/[user-raw].”
Figure : The Pathauto settings on the “Automated alias settings” tab under the URL aliases administration sectionThese settings will now take care of all new content that we create, but another thing that we want to account for is the content that we have already created. Currently, our new Help page that we created has a URL likeEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Drupal’s Revision Tracking
- InhaltsvorschauBe it online or in your local word processor, everyone has had that moment, right after you hit Submit or Save…where you wish you hadn’t. Or sometimes you lovingly craft something, hand it off to someone else for review, and they go a bit crazy changing everything. What you want at that moment is the previous version of your document. Luckily for us, Drupal includes that ability right in core. As you make changes to your content over time, Drupal can keep track of each version of the content, so you can go back to when your work was just the way you wanted it. In Drupal, each recorded change is called a revision.Drupal revisions store a new copy of a node rather than overwriting it each time you save. However, this doesn’t happen by default; you need to tell Drupal you want to keep a copy. A user with “administer nodes” permission can enable revisions on a case-by-case basis by checking the “Create new revision” checkbox on the node edit form in the Publishing options. This is fine if you don’t want to keep every copy in your database and if the proper permissions are assigned to those who will need them. If you’d rather, you can also enable the option per content type. This way you don’t need to remember to check the box every time you edit something and you don’t need to give out more permissions to your users than you would otherwise like to.In addition to tracking the different versions of the text, you can also make notes pertaining to each revision using the “Log message” box. This is very useful for explaining what changes you made and why. Reasons for changes may seem obvious to you at the time you make them, but that doesn’t mean they will be apparent to others working on the same document with you, and they may not even make sense to you six months down the line. It is always a good idea to make notes about your changes so you and others can easily follow along.Once you have created a revision of a node, you will see a new tab appear next to your standard “View” and “Edit” tabs called “Revisions.” Within the “Revisions” tab you have a handy place to review old versions, each listed with a link to the revision, the date and author information, as well as the log message, if any, that was entered when it was saved. You can even tell Drupal to revert to a particular revision, replacing the content in the View tab. It does not actually delete the content, but creates yet another revision that you could revert to later if you change your mind. If you do want to actually delete a revision permanently from the database, there is a handy link for that as well.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Hands-On: Revisions and Diff
- InhaltsvorschauSo now let’s examine how the revision system works. To do that, we need to check some settings and then make some changes to our content. Once you have learned how the core Drupal revisions work, we’ll enhance them using the Diff module to make them even more informative.We want to keep track of all changes to all content, whether it’s on a Wiki or Page type. As mentioned previously, revisions are not created by default, but we can change that. The node publishing option defaults can be configured per content type. We already set this up for the Wiki page content type when we created it, but our Page content is not configured for this. Let’s go turn it on so we make sure we get every revision:
- Go to Administer→Content management→Content types (admin/content/types) and click the “edit” link for the page type.
- Scroll to the bottom. Under “Workflow settings: Default options,” check the “Create new revision” checkbox.
- Click “Save content type” to submit the form.
For the SGA site, we want all users to be able to keep track of what others have done and see these revisions. They also know that they are working with a relatively trusted group of users, so they want to allow anyone to undo changes if needed. A quick trip to “User management” will take care of that:- Go to Administer→User management→Permissions (admin/user/permissions), and configure the permissions as shown in .
Table : Configuring revision permissions Permission: node moduleanonymous userauthenticated usereditoradministratorrevert revisionsCheckedview revisionsChecked
- Click the “Save permissions” button to save them.
Let’s make some content changes and see how we can use the revisions:- Go to the Help page we created earlier and click the Edit tab.
- Change the text in the Body field by putting quotes around the path to create new wiki pages and removing the word “Wiki,” so that it reads like this:
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: New Pages and Recent Edits with Views
- InhaltsvorschauDrupal core comes with a module called Tracker, which makes a handy page of recently updated posts. What that page offers, though, is not quite what our SGA needs. The tracker module lists all new content, including edits, and counts new comments added to a post as an “update.” This means that the most recent post listed here may not have actually had any content changed within it. It also mixes newly created content with updated content. The SGA specifically would like to have two lists: one that just shows newly created content and another that shows only when the content itself has been edited.As the core Tracker module does not provide us this flexibility, we are going to use the Views module, introduced in , to create some custom lists. The Views module comes with a default view that replicates the Tracker listing. We will use that as a base for the two lists we need to make: the “Recent posts” and the “Recent edits” listings.
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Views package
- Views
- Views UI
- Go to Administer→Site building→Views (admin/build/views) and click the Enable link for “Default Node view: tracker.” Then click the Edit link (admin/build/views/edit/tracker).
- Ensure that the Defaults display is highlighted.
- Limit the visibility of this view to authenticated users by entering the Basic settings shown in .
Table : View Basic settings for the “Recent posts” view Defaults: Basic settingsValueAccessType: By role
- As this view is only concerned with updates to content, under Fields, click on the “Node: Last comment time” field and click the Remove button to remove it from the view.
- Replace the last comment time with the post date by clicking the
(+)(plus) icon in the Fields group and adding the “Node: Post date” field. Give it a Label of “Post date.” - Because the recent content should be listed across the whole site and not limited per user, under Arguments, click on the User: Uid argument and click the Remove button.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauWe have satisfied the needs of our group and managed to pull together a pretty nice collection of modules to create a good, basic wiki. However, there are even more available modules that you can use to add all kinds of bells and whistles. Here are some additional modules that would add some extra special wiki sauce to our site:
- PEAR Wiki Filter (http://drupal.org/project/pearwiki_filter)
- The nice thing about the PEAR Wiki Filter is that with one module you can choose from several popular wiki markup syntaxes like MediaWiki, TikiWiki, and Creole. The downside to this module is that it is a little more involved to install. You need to separately download the PHP PEAR package for each syntax you wish to use as well as the base Text Wiki package.
- Table of Contents (http://drupal.org/project/tableofcontents)
- Often, when you have long pages that are used as reference documents, you can end up with a long page that is somewhat hard to navigate. The Table of Contents module will look through the page to find HTML headers and use those to build a small clickable table of contents for just that page. This table of contents can be added to the page in a block.
- Talk (http://drupal.org/project/talk)
- The Talk module moves the comments on a wiki page to a separate “Talk” page, to emulate the “Discussions” separation found in many wiki packages.
- The Views module’s “Backlinks” view (included with http://drupal.org/project/views)
- The Views module comes with a default view named “Backlinks,” which you can easily enable in the Views administration page. “Backlinks” will give you a list of all the other pages on the site that are referring to the page you are viewing at the moment.
- Taxonomy (core)
- Another nice touch we can add to the site is built right into core Drupal—. Taxonomy can allow you to group your wiki content together. For instance, our SGA may want to have a vocabulary of “Document category” that has the following terms: policy, meeting notes, and event planning. This way they can quickly get lists of all content according to its category. Another sometimes useful way to use taxonomy is to create a free-tagging vocabulary so that the members can add keywords to the content as they are creating and editing. For more information on using taxonomy, please refer to .
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauIn this chapter, we introduced several new modules: the Markdown and Freelinking filter modules, plus Pathauto, Token, and Diff. With the Markdown and Freelinking modules, we reviewed some information about Drupal’s filters and input formats and saw how to actually build a new input format with some contributed filters. Using Pathauto and Token, we learned about Drupal’s paths and how to make them more user- and search engine–friendly. We talked about Drupal’s core revision tracking and then saw how to enhance that even further using the Diff module. Lastly, we put your new Views knowledge from to use by creating some custom Views that do exactly what the SGA needed. We created a nice, solid wiki site that will allow users to work together to create and edit the content they need.For more information about wikis in Drupal and to see how others are creating them, check out the Wiki working group at http://groups.drupal.org/wiki.Here are the modules that we referenced in this chapter:
- BBCode: http://drupal.org/project/bbcode
- Freelinking: http://drupal.org/project/freelinking
- Liquid Wiki: http://drupal.org/project/liquid
- Markdown filter: http://drupal.org/project/markdown
- Path redirect: http://drupal.org/project/path_redirect
- Pathauto: http://drupal.org/project/pathauto
- PEAR Wiki Filter: http://drupal.org/project/pearwiki_filter
- Table of Contents: http://drupal.org/project/tableofcontents
- Textile: http://drupal.org/project/textile
- Wikitools: http://drupal.org/project/wikitools
These are some other resources that we referenced and community resources for learning more about the new concepts introduced in this chapter:- Filter-related modules: http://drupal.org/project/Modules/category/63
- Markdown text-to-HTML converter: http://daringfireball.net/projects/markdown/
- Wiki working group: http://groups.drupal.org/wiki
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 6: Managing Publishing Workflow
- InhaltsvorschauFor large, content-driven web projects, building the initial site structure and getting the design “just so” is only the beginning of the work. If more than a small handful of people are writing content for the site, the process of reviewing, revising, and publishing individual articles can be a Herculean task. Newspapers, online magazines, and even many large blogs with multiple contributors need tools to ensure that editors can manage the review process. In this chapter, we’ll be using Drupal’s built-in workflow management options and automation tools, as well as a number of administrative modules, to build “workflow management tools” for a news site.This chapter introduces the following modules:
- Trigger (core)
- Performs common tasks when specific events occur on the site
- Workflow (http://drupal.org/project/workflow)
- Allows administrators to define custom publishing states for content, like “In review” and “Ready for publication”
- Workspace (http://drupal.org/project/workspace)
- Gives contributors quick access to all of their own content
- Views Bulk Operations (http://drupal.org/project/views_bulk_operations)
- Allows administrators to perform common actions (like publishing or rejecting content) on multiple pieces of content at a time
If you would like to participate in the hands-on exercises in this chapter, you should install Drupal using the Newspaper installation profile from the book’s sample code, which creates the example website on your web server. The completed website’s administration tools will look like the image pictured in and found at http://newspaper.usingdrupal.com. For more information on using the book’s sample code, see the Preface.
Figure : The Twin City Arts websiteJo and Catherine have spent the past year building an online news site for artists, writers, and creative types living in Minnesota: Twin Cities Arts. It’s a great combination of volunteer reporting on developments in the art scene, creative writing, and interviews with area personalities. As the site grows, though, it’s become obvious that the “honor system” approach to managing site content won’t work for much longer. Low-quality stories and inaccurate news posts have started hitting the front page, and Jo and Catherine want to build a bit more structure into the publishing process before things get out of hand.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- Inhaltsvorschau
Figure : The Twin City Arts websiteJo and Catherine have spent the past year building an online news site for artists, writers, and creative types living in Minnesota: Twin Cities Arts. It’s a great combination of volunteer reporting on developments in the art scene, creative writing, and interviews with area personalities. As the site grows, though, it’s become obvious that the “honor system” approach to managing site content won’t work for much longer. Low-quality stories and inaccurate news posts have started hitting the front page, and Jo and Catherine want to build a bit more structure into the publishing process before things get out of hand.After a few conversations with the two editors and several of their writers, we’ve got a good idea of the essentials that are needed for the site. Their writers should be able to create news stories whenever they want to, but as editors, Jo or Catherine should review and approve stories before they’re accessible to visitors. When a writer is finished with a draft, the editors should be notified via email so they can quickly review and approve the story for publication on the site. Jo and Catherine want to be able to send an article back to a writer with suggested changes, and the writer should be notified of the suggestions via email.As there are multiple stages in the process of getting an article published, all of the people involved need overview screens where they can review the list of items that need their attention. The editors in particular should be able to approve or reject multiple articles at once to save time on busy news days.Drupal core allows administrators to change the default publishing settings for each content type, ensuring that stories posted by contributors won’t immediately show up until an editor publishes them manually. However, the grunt work of checking for new unpublished posts, reviewing them, editing them, publishing them, and then saving the changes is cumbersome for sites with a lot of activity. We’ll be using a collection of useful modules to streamline that process and match the requirements.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: First Steps
- InhaltsvorschauOur first step will be to change the default workflow settings for the Story content type that we are using for our articles:
- Go to Administer→Content management→Content types (admin/content/node-type) and click the “edit” link for the Story content type.
- Scroll down to the “Workflow settings” section of the form and expand that .
- Uncheck the Published checkbox.
- Click the “Save content type” button to save the changes.
- Go to Administer→User management→Permissions (admin/user/permissions) and we’ll make sure that all users can create stories, that editors have full access to all of the submitted content, and that site administrators can administer actions, which will be covered later in the chapter. Set the permissions as indicated in .
Table : Content permissions Permissionanonymous userauthenticated usereditorsite administratornode moduleadminister nodesCheckedCheckedcreate story contentCheckededit own story contentCheckedsystem moduleaccess system administration pagesCheckedCheckedadminister actionsChecked
- Click “Save permissions.”
Now, if you log on as user, you can submit stories, but they won’t appear on the front page and “normal” users can’t see them. Logging in as editor and visiting Administer→Content management→Content (admin/content/node) will show you those articles and allow you to read and publish them.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Actions and Triggers
- InhaltsvorschauWith the changes we’ve made, writers can submit stories whenever they want to, but they’ll stay hidden until Jo or Catherine publishes them manually. A new problem arises, however: how do the editors know when a new article is ready for review? Right now, they need to check the site every few hours just to be sure they haven’t missed anything.That’s where one of Drupal’s powerful but little-known features comes in: Actions. In Drupal parlance, an action is a single, easily encapsulated task like publishing a node, displaying a message to the currently logged-in user, or sending a prewritten email to a particular address. Third-party modules can quickly trigger these actions when specific conditions are met or certain events occur.How is this useful? Many modules focus on providing useful management tools to users: for example, clicking on a link below a node to unpublish it, or automatically banning users if they post offensive content. What happens, though, if your site needs to send email to an administrator when offensive content is posted, rather than automatically banning the user? What if you need that link below a node to promote it to the front page, rather than unpublishing it? Instead of hardcoding those behaviors, module developers can allow administrators to pick from the list of available actions, like those shown in , and then customize the specifics themselves. This feature gives administrators and other site builders much more flexibility—without requiring module developers to anticipate and account for every possible task.
Figure : Available default Drupal actions
Figure : The Trigger module allows actions to be assigned to system eventsThere are two types of actions: basic actions, which perform a simple task, and advanced actions, which are configurable. Many Drupal administration tasks can be performed using actions. Banning users, promoting content to the front page, adding taxonomy terms to content, unpublishing comments that contain offensive language, sending email, and so on, are all possible. In addition, contributed modules can add new actions to Drupal. “Send a text message to a phone number” or “Add the currently logged-in user to a new security role” are all examples of useful actions. Some, like the built-in “Send an email” action, are also configurable. They allow you to create multiple copies of the action, each with different settings. For example, one email action could notify the site administrator that a new user has been created, while another email action notifies the author of a node when a comment is posted to it.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Actions and Triggers
- InhaltsvorschauAs mentioned earlier, some actions need to be configured before we can assign them to specific events. We need to set up the customized email message that will be sent whenever content is posted on the site, as well as a message that the writers will see when they submit their stories, like the one shown in .
Figure : Message displayed to the author- Go to Administer→Site configuration→Actions (admin/settings/actions) and click the select list under “Make a new advanced action available,” as shown earlier in . You will see a number of actions we can set up. Select the “Send e-mail...” action and click the Create button.
- Enter the information shown in into your form.
Table : Settings for the editor notification email action FieldValueDescriptionNotify editorRecipient[your email address]SubjectNew article submitted by %usernameMessage%username submitted a new %node_type titled “%title” for approval at %site_name.---%teaser---To review the full article and publish or delete it, visit %node_url.It’s important to note that certain special placeholders are being used in our messages. Whenever the action is triggered, %username, %title, and %node_url are all automatically replaced with information from the node that was submitted. These are similar to the tokens used in Token module in the previous chapter. You can see the full list of available placeholders in the help text under the Message text area.
- Click the Save button and you will be returned to the main Actions screen, where you will see our new action listed under the “system” Action type, as seen in .
Figure : The Notify editor action in the actions list- We also want to display a message to the author of the article, so that the authors know that their articles haven’t simply vanished. We’ll set up a new kind of action for this. Select “Display a message to the user...” from the “Make a new advanced action available” action select list and then click the Create button.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Workflow Module
- InhaltsvorschauSo far, we’ve been relying on the built-in “published” flag that Drupal provides for every piece of content. When it’s unchecked on the node editing form, only users with the “administer nodes” permission are allowed to view the content. That’s enough for some sites, but it doesn’t give our writers and editors as much control as they need. For example, there’s no way for a writer to mark a story as an in-progress draft and come back to it later. In addition, there’s no easy way for an editor to tell a writer that an article needs more work—the editor must contact the author manually.This problem is exactly what the Workflow module (http://drupal.org/project/workflow) was designed to solve. It allows site administrators to set up predefined steps, called states, through which every piece of content must pass before publication. A complex site with strict legal requirements might need “Editorial review,” “Legal review,” “Executive approval,” and “Ready to publish” states. When a node is in one of those states, only users in specific roles are allowed to move it to the next state, ensuring that the right people give the content their stamp of approval before it goes live.The selection of workflow states can be done directly during node creation and editing through a new fieldset added to the node form, as seen in . Along with changing the state, a user can also leave a comment in the workflow log. This way others can see reasons or notes about a change. Workflow also allows users to schedule a state-change for a specific time. Moving a page from “Executive approval” to “Ready to publish,” for example, can be scheduled for 8:00 a.m., even if the VP made the decision at 11:00 p.m. the previous night.
Figure : Workflow states selectionIn addition to the node form controls, Workflow provides a tab to the node form next to the View and Edit tabs. This tab shows the same state and scheduling controls, along with the Workflow History log that tracks every state change and displays any comments that were left. An example of the log is shown in .Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Creating a Workflow
- InhaltsvorschauFor the Twin City Arts site, we are going to need a few states for stories to pass through. We will need a “Draft” state for writers to save in-progress work that isn’t ready to be reviewed yet, and we will need a “Review” state once a piece is submitted. Finally, we will need an “Approved” state where the story is published for all to see on the site.
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following module:
- Workflow package
- Workflow
- Then go to Administer→Site building→Workflow (admin/build/workflow). You will see a message that says, “No workflows have been added. Would you like to add a workflow?” To create one, click the “Add workflow” tab (admin/build/workflow/add).
- Enter a Workflow Name of “Article publication” and click the “Add workflow” button.
- We are brought to the main workflow listing page shown in , and we can see that our new “Article publication” workflow has been added to the list. At the bottom of the page is a list of content types. We want our workflow to apply to the Story content type, since that is what we use for articles. Click the select list in the Workflow column for the Story content type and select “Article publication.” Click “Save workflow mapping” to save the changes.
Figure : Article publication workflow settings- We now have a workflow assigned to Story content, but it doesn’t do anything yet. We need to add the various states we want for our articles. Click the “Add state” link. Enter “Draft” as the “State name” and click Save.
- Follow the same process, clicking “Add state,” and adding each of the other two states: Review and Approved. Your Workflow list should look like when you are done.
Figure : List of workflow states for the Article publication workflow- Fill out the workflow transitions by checking off the roles, following , as shown in . Note that we are intentionally not setting anything in the “Approved” row, because once it is approved and published it won’t go “backward” to either the “Draft” or “Review” states.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: The Workspace Module
- InhaltsvorschauWe’re definitely getting closer to the functionality that Jo and Catherine need, but there’s one glaring problem that still remains. Writers can post new content and leave it in the “Draft” state if they don’t want it to be reviewed yet. What happens when they want to come back and finish the work, though? Because it’s still unpublished, the story won’t be included on any of Drupal’s normal listing pages! Our writers will be able to return to the drafts only if they remember the numeric ID of their articles, and that’s asking a bit much of volunteers.Using the Views module, we could build a custom listing page that shows all nodes—including unpublished ones—by the current logged-in user. However, the Workspace module (http://drupal.org/project/workspace) can also handle this feature and is much easier and faster to set up. It gives each user his own personal page that lists the nodes, comments, and files that he’s posted to the site, as shown in . By default, Workspace will add a new menu item, “My workspace,” to the navigation to access the page. You can also configure it to add a link to each user’s workspace directly on his user page.
Figure : The “My Workspace” page, listing a user’s contentIn addition to the view-like page, Workspace also provides a quick shortcut to create new content. A list of content types that the user is allowed to create will appear in a drop-down select list on his workspace page with a handy “Add new item” button that will take him immediately to the content creation screen, such as Create content→Story (node/add/story). That makes it an easy one-stop dashboard for frequent contributors.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Create Workspaces
- InhaltsvorschauThe Workspace module is a snap to set up. When we are done with a few short steps, we’ll have something like for all of our users.
- First, go to Administer→Site building→Modules (admin/build/modules) and enable the following module:
- Other package
- Workspace
- That’s it! You should now see a “My workspace” link in the navigation menu, and each user on the site will have her own workspace as well.
- At Administer→User management→Permissions (admin/user/permissions), you’ll see that the Workspace module also defines some permissions. If users are given “administer own workspace” permission, they’ll be able to configure settings such as how many items are displayed. Use the permission assignments shown in and click “Save permissions” when done.
Table : Settings for workspace permissions Permission: workspace moduleanonymous userauthenticated usereditorsite administratoradminister own workspaceCheckedCheckedCheckedadminister workspacesCheckedview all workspacesChecked
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Views Bulk Operations
- InhaltsvorschauWe’ve accomplished quite a bit for the editors of our website. Now they can move articles from one state to another, send them back to writers for revisions, receive notices when stories are ready for review, and automatically publish them when they’re ready for consumption. However, editors still have to work with the articles one by one, a troublesome limitation when the site has been swamped with me-too news stories or low-quality poetry.
Figure : The Drupal core default content administration view
Figure : The “Workflow summary” view using Views Bulk OperationsDrupal provides a built-in content administration page at Administer→Content management→Content (admin/content/node). It allows administrators to list 20 pieces of content at a time, and to perform bulk operations on them, like publishing and unpublishing, which you can see in . However, this screen doesn’t take advantage of the actions system, and it’s impossible to customize what information is listed in the table.The Views Bulk Operations module (http://drupal.org/project/views_bulk_operations) is designed to overcome that limitation. It provides a new style of view called “Bulk Operations.” It displays the contents of the view much like a standard table-style view, with columns and rows and headers. However, it puts a checkbox next to each node and places a drop-down list of actions at the top of the view. The result is an easy-to-customize management form with all the capabilities of Drupal’s content administration screen, but with far more flexibility. You can see an example of the bulk operation view in .In addition, it’s possible to customize the actions that appear in the drop-down. Using that capability, you can give users in different roles access to more powerful administration screens. A moderator for a message board, for example, might see an administration screen with the “Unpublish content” and “Email administrator” actions. An administrator could be given access to another view that includes the “Ban user” and “Delete content” actions in its list of options.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Building an Administration Page
- InhaltsvorschauFirst, before we get to the view, we need to set up specific actions to reject and approve content using our workflow states. This will allow the Views Bulk Operations module to list the Reject and Approve options easily.
- Go to Administer→Site configuration→Actions (admin/settings/actions).
- Select “Change workflow state of post to new state...” from the “Make a new advanced action available” drop-down and click Create.
- Fill out the new action’s form as shown in and save it.
Table : Settings for the Approve post action SettingValueDescriptionApprove postTarget stateApproved - Do the same thing again, only this time use “Reject post” for the Description field, and select Draft as the “Target state.” Click Save to complete it.
We’ve now set up specific, reusable actions to reject and approve nodes. Thanks to the work we did earlier, whenever these actions are triggered, all the appropriate emails will be sent and content will be published as soon as it’s approved, based on the workflow and trigger rules we set up.The Workflow module already provides a simple view listing all of the site’s content, and what state each piece of content is currently in. Now, we need to alter this view to take advantage of the Views Bulk Operations module.
Figure : Views Bulk Operations settings- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Other package
- Advanced Help
- Views package
- Views
- Views Bulk Operations
- Views UI
- Now, when we go to Administer→Site building→Views (admin/build/views), we will see the “Default Node view: workflow_summary” view listed. Click the Edit link for that view (admin/build/views/edit/workflow_summary).
- In the “Basic settings” section, click Style: Table, change it to Bulk Operations, and click Update.
- In the “Defaults: Style options” configuration screen that appears below, in the “Selected operations” section, check the following options, and click Update:
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauWe now have our new editorial workflow in place. We’ve met the needs of our client, but there are some other modules that are also worth checking out:
- Flag (http://drupal.org/project/flag)
- Flag, which is covered in more detail in , could be used to allow quick in-place approval of articles without going to the edit page or the overview page.
- Workflow Fields (http://drupal.org/project/workflow_fields)
- You can change specific CCK fields based on a node’s state, making them read-only or hiding them entirely, depending on what stage of the publishing process the content is in. For example, although it might make sense for the legal team to read the content of a new article and reject or approve it, they should probably not be allowed to make their own edits.
- Workflow Graph (http://drupal.org/project/workflow_graph)
- This module can present the history of one piece of content as a visual graph, mapping out which contributors to the site have changed its states at what time. Though this isn’t necessary for simple sites, it can make keeping track of complex editing processes much easier.
- Nodequeue (http://drupal.org/project/nodequeue)
- This module is often used on online news sites, as it allows for displaying arbitrary articles in a list with a user-specified order, such as maybe an Editor’s Picks list of articles. Nodequeue also has actions integration, which allows you to do things like automatically add new articles to queues on a per-topic basis.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauCongratulations! The Twin City Arts website now includes all the major features that the staff wanted. We’ve used the Workflow module to create a richer set of “states” for content to exist in, preventing collisions when editors review rough drafts that writers haven’t finished. We’ve used actions and triggers to handle notifying editors and writers when articles need their attention, and we’ve used the Views Bulk Operations module to give editors a way to manage large groups of articles at a time. Finally, we used the Workspace module to give writers a simple, one-stop location to view their rough drafts, their in-review articles, and their previously published pieces.Here are the modules that we referenced in this chapter:
- Nodequeue: http://drupal.org/project/nodequeue
- Trigger: core
- Views Bulk Operations: http://drupal.org/project/views_bulk_operations
- Workflow: http://drupal.org/project/workflow
- Workflow Fields: http://drupal.org/project/workflow_fields
- Workflow Graph: http://drupal.org/project/workflow_graph
- Workspace: http://drupal.org/project/workspace
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 7: Photo Gallery
- InhaltsvorschauIf a picture says a thousand words, it’s important that a site have a strong foundation for managing images. The flexibility of Drupal allows for the management of images in a variety of ways and can scale from a one-person portfolio to millions of users uploading photos on a fansite.This chapter introduces the following modules:
- ImageField (http://drupal.org/project/imagefield)
- A CCK field that allows image uploads
- ImageCache (http://drupal.org/project/imagecache)
- Automatically resizes images to predefined dimensions and caches them for later retrieval
- Custom Pagers (http://drupal.org/project/custom_pagers)
- Creates custom previous/next pagers
If you would like to participate in the hands-on exercises in this chapter, install Drupal using the Photo Gallery installation profile from the book’s sample code. This will create the example website on your web server. The completed website will look as pictured in and at http://gallery.usingdrupal.com. For more information on using the book’s sample code, see the Preface.In order to complete this chapter, you must have the Clean URLs feature working, and your version of PHP must have the GD Library installed. See the “ section, later in this chapter, for more information.
Figure : The Robinsons’ photo gallery websiteThe Robinsons have a large extended family with whom they have trouble keeping in touch. The family has long been pestering their web-savvy son Fritz to build a website where they could share family stories and full-resolution photos. Finding himself with a weekend and no homework, Fritz decides to set up the family photo-sharing site using Drupal.The Robinsons want the ability to let family members submit photos. When uploaded, photos should automatically resize down to a thumbnail view, but also allow for the download of a full-resolution version. They want to be able to put the photos into different galleries and tag the photos with keywords. And finally, they want their family members to be able to comment on the photos!Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- Inhaltsvorschau
Figure : The Robinsons’ photo gallery websiteThe Robinsons have a large extended family with whom they have trouble keeping in touch. The family has long been pestering their web-savvy son Fritz to build a website where they could share family stories and full-resolution photos. Finding himself with a weekend and no homework, Fritz decides to set up the family photo-sharing site using Drupal.The Robinsons want the ability to let family members submit photos. When uploaded, photos should automatically resize down to a thumbnail view, but also allow for the download of a full-resolution version. They want to be able to put the photos into different galleries and tag the photos with keywords. And finally, they want their family members to be able to comment on the photos!Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Implementation Notes
- InhaltsvorschauYou probably expect the task of building a photo gallery to be easy, but given the wide array of options available in Drupal, it can quickly turn confusing. The good news is that a site built with CCK and Views, such as the job website in , can quickly be extended to create a highly customized image gallery.Image handling in Drupal has long been a distributed effort between several cooperating (or competing) modules. The Image module (http://drupal.org/project/image) was the universal solution in Drupal 4.6 and 4.7, but with the advent of CCK, several new modules appeared that leveraged this new, more flexible system. Because the Drupal community’s development trends are headed toward websites built around CCK and Views, we’re going to build our site around this newer approach, building on the basic functionality of CCK and Views.ImageField (http://drupal.org/project/imagefield) is a module that provides a reusable image upload field to CCK, which we’ll be able to use to upload our photos.Despite its name, the ImageCache module (http://drupal.org/project/imagecache) does much more than simply cache images. It is often paired with ImageField, because although ImageField handles the upload and storage of images, it does not provide any way of creating thumbnails. ImageCache can not only create thumbnails, but also chain together several image manipulations such as crop, rotate, scale, desaturate, and sharpen to create completely customized displays of images.The display of images in a gallery can be made from a few pages created by the Views module. Because ImageCache and ImageField provide Views integration, you’ll be able to select any desired images created with ImageField, and then ImageCache will scale those images down for display in the view.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Spotlight: ImageField
- InhaltsvorschauBuilding on the flexibility of CCK, any module in Drupal can provide a reusable field that can be used to extend your content types. Fields that handle things like text or numbers are bundled with CCK, but you can just as easily add fields that allow you to upload audio and video files, click web links, and more. These other field types are separate projects on the Drupal.org website, available under the “CCK” category (http://drupal.org/project/Modules/category/88).The ImageField Module, available from http://drupal.org/project/imagefield, is one such specialty field that provides a reusable field for image handling, as shown in . Like other CCK fields, you can configure an image field to allow multiple values, so any number of images can be uploaded to a single node. You can even add multiple fields to a single content type, in case a piece of content has the need for multiple images, each with specialty uses.
Figure : An image field with options enabled for “Alternate text” and “Title”After enabling the module, ImageField puts a new field on the fields form for setting up a new or existing content type. Like other CCK fields, an image field is added to a content type at Administer→Content management→Content types (admin/content/types). The form for configuring an image field is displayed in .
Figure : The widget configuration options for an image fieldA few of the options on this form are common among all CCK fields, such as Label, Widget type, Required, and Number of values. These fields behave the same for an image field as they do for other fields, as described in the introduction to CCK in . The other options listed here are unique to ImageField:- Maximum resolution
- If a user uploads an image that is too large, the image is scaled down proportionally to fit within the maximum resolution.
- Minimum resolution
- If a user uploads an image that is too small, ImageField prompts the user for a larger one.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Uploading Photos
- InhaltsvorschauTo begin, we need to handle some basics: creating a form with which to upload photos, and some taxonomy terms that we will use to create a browsable photo gallery.The first thing that we’ll need for our photo gallery is a new content type for photos, called Photo. This new type will let users upload full-resolution photos through .
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- CCK package
- Content
- FileField
- ImageField
- Core – optional package
- Taxonomy
- Go to Administer→Content management→Content types (admin/content/types) and add a new content type by clicking on the “Add content type” tab. Create a content type called Photo, using the settings indicated in .
Table : Settings for the new Photo content type FieldValueIdentificationNamePhotoTypephotoDescriptionA photo containing a Robinson family member or friendSubmission form settingsTitle field labelTitleBody field label
- After creating the Photo type, you’ll be redirected back to the list of content types. We’ll now add an image field to the new Photo content type. Click the “manage fields” link next to the Photo type (admin/content/node-type/photo/add_field). Enter the values as in .
Table : Settings for adding a photo field to the Photo content type FieldValueLabelPhotoField namephotoSelect a field typeImageSelect a widget typeImage
- After creating the new field, you’re presented with the form to configure it (admin/content/node-type/photo/fields/field_photo). Enter the values as in . Though most of these settings are self-explanatory, the maximum resolution for images has a special meaning for a value of 0, meaning that there is no limit to the resolution of the uploaded image. As one of the family goals was for full-size image swapping, we’ll leave this at the default value of 0. We’ll also upload all pictures to a subdirectory called
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: ImageCache
- InhaltsvorschauIf you uploaded an exceptionally large image during the previous hands-on steps, chances are good that you managed to break your site’s layout. To prevent this, you’ll want to scale these images so that they’re a consistent size, and create thumbnails for use in listing pages. To help with this task, the ImageCache module will provide these options and many more for displaying images.When it comes to file handling, ImageCache is one of the most exciting modules for Drupal. Despite the name, ImageCache does much more than cache images. It is in fact a full image manipulation tool, which will likely serve as the basis for image handling in a future release of the Drupal core.The image manipulation provided by ImageCache allows a series of actions such as cropping, scaling, or resizing to be combined into what is called an image preset. By combining actions, you can create a customized display of your images. shows the result of a preset that combines a crop action with rotate to make a square image that is rotated 90 degrees.
Figure : An image preset using two actions: scale and crop, then rotateThe “cache” part of ImageCache comes after the image has been manipulated. The image is generated on the fly, then saved in a directory with the same name as the ImageCache preset. This way, images are only manipulated once, then saved to the disk. illustrates the ImageCache workflow when an image is requested.
Figure : ImageCache workflow for creating a thumbnailThe main ImageCache administration panel at Administer→Site building→ImageCache (admin/build/imagecache), shown in , displays a list of the presets available on the site. An image preset starts as nothing but a name, describing the actions that are performed on this style of image. You can add, edit, or delete presets, as well as “flush” them. The Flush option lets you clear out all created images for a preset. Because images are generated on the fly, you can delete all the thumbnails on your site at any time and they’ll be re-created the first time they’re requested. You might try flushing the cache for a preset if images somehow become out of date with the original.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: ImageCache
- InhaltsvorschauThanks to the previous section, we can now upload and categorize photos, but listings of photos are displaying several full-resolution images—surely not what the Robinson family wants! We need to create scaled-down versions of the images while leaving the original images intact. First, we’ll set up ImageCache to provide us with thumbnails, and then configure our Photo type to use these thumbnails:
- Check that Clean URLs are enabled at Administer→Site configuration→Clean URLs (admin/settings/clean-urls).
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- ImageCache
- ImageAPI
- ImageAPI GD2
- ImageCache
- ImageCache UI
Let’s set up a few presets to scale down the images: the first one a “thumbnail” size that’s a small 120-pixel-wide square, and the second a “preview” size that maxes out the image for display on photo node pages (which maxes out the image widths at 480 pixels to prevent our layout from breaking):
Figure : ImageCache preset configuration screen- Go to the ImageCache settings page at Administer→Site building→ImageCache (admin/build/imagecache). Click the “Add new preset” tab.
- Enter the preset name “thumbnail” in the “Preset namespace” field and click the Create New Preset button. This will take you to the preset configuration screen pictured in .
- On the next page, configure the thumbnail preset. In the New Actions fieldset, click Add Scale and Crop. Enter the values from and shown in for the scale and crop action, to create image thumbnails as 120-pixel-wide squares. Click Add Action when finished.
Table : Settings for the “thumbnail” scale and crop action SettingValueWeight0Width120Height120
Figure : Settings for the ImageCache actions- That completes the configuration of the thumbnail preset. Return to the main page at Administer→Site building→ImageCache (admin/build/) and click the “Add new preset” tab. Enter “preview” into the Preset Namespace text field and click the Create New Preset button.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Gallery View
- InhaltsvorschauWe now have the process for uploading an image pretty much finished, and display of individual photos isn’t looking too bad either. The shortcoming of our site right now is the display of thumbnailed images on a single page. It would be preferable if the images were laid out in a grid-like fashion, allowing many images to be displayed in a small area. To accomplish this task, we can set up a view using the Views module. When complete, this section will look as pictured in .
Figure : Completed gallery view- Go to at Administer→Site building→Modules (admin/build/modules) and enable the following:
- Other
- Advanced Help
- Views
- Views
- Views UI
- Go to the Views administration page at Administer→Site building→Views (admin/build/views). Click the Add tab at the top of the page to make a new view. Create a new view using the settings from .
Table : Basic Information for the gallery view FieldValueView namegalleryView descriptionA gallery display of imagesView typeNode
- Configure the Basic settings of the new view using the information from .
Table : Page settings for the gallery view Defaults: Basic settingsValueTitleGalleriesStyleStyle: GridNumber of columns: 4Alignment: VerticalUse pagerFull pagerItems per page20More linkCreate more link: CheckedEmpty TextNo photos yet!
- Find the Fields section of the view, click the
+(plus) icon, check the “Content: Image: Image (field_photo)” field and click Add. Configure the field with the settings in and click Update.Table : Default fields for the gallery view Defaults: FieldsValuesContent: Image: Image (field_photo)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Latest Photos Block
- InhaltsvorschauSo even though we have a pretty convincing gallery view setup, our home page is still less than desirable with the default listing of images. Let’s spice it up with another special view that shows the latest images uploaded anywhere on the site. To speed up the process, we can clone the gallery view and then just make a few tweaks. When completed, the site’s front page will look as pictured in .
Figure : Front page with the Latest Photos blockAnother option besides cloning the view is to make another display within the existing gallery view. However, because we’ll need to remove a filter and we could possibly change the image field to use a different ImageCache preset, we’ll need to override a lot of the view defaults. When in a situation like this, if you’re doing more overriding than inheriting, it’s a good idea to start with a new view rather than building more displays into an existing one.- Go to the views administration page at Administer→Site building→Views (admin/build/views).
- In the row for our gallery view, click the Clone link. This makes a copy of the gallery view, where we can just make a few changes.
- Give the new view the basic information from .
Table : Basic information for the latest_photos view FieldValueView namelatest_photosView descriptionA list of the latest photos on the site
- Click Next to begin editing the cloned view. We no longer need the Page display. So click the Page display tab on the left, then click the “Remove display” button. Click Save to remove the display entirely.
- We also no longer need the Taxonomy: Vocabulary filter. Click on the Taxonomy: Vocabulary link in the Filters area. In the configuration for the filter, click the Remove button.
- In the Basic settings for the view, change the Title to Latest Photos.
- Add a new block display to the view. Select Block from the list of display types on the left side of the Views interface and click the “Add display” button.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Custom Pagers
- InhaltsvorschauWhat’s still showing a lack of tender love and care, however, is the photo asset page. To view a list of photos, a user has to click the photo, return to the previous page, and then click the next photo. This process could be simplified quite a bit if there were previous and next buttons on the photo asset page. The Custom Pagers module (see http://drupal.org/project/custom_pagers) can take any view (such as our gallery view) and create a simple pager on node pages for the previous and next items in the view.shows what the photo pages will look like when completed with this .
Figure : Photo pages, now with paging
Figure : Custom Pagers configuration for gallery pager- Go to Administer→Site building→Modules (admin/build/modules), enable the following modules, and click “Save configuration”:
- Other package
- Custom Pagers
- Token
- Go to the administration page for Custom pagers at Administer→Site building→Custom pagers (admin/build/custom_pagers).
- Click the “Add a new custom pager” link at the bottom of the page.
- Populate the form with the values from , as shown in , and click Submit.The [term] and [term-id] tokens will always use the top term assigned to the node. Because we set the Gallery vocabulary to a −1 weight (and the Tags vocabulary to a 0 weight), the term name and ID for the current gallery will populate this value dynamically.
- Now that we have a custom pager set up and ready to display as a block on the page, make a visit to the blocks administration page at Administer→Site building→Blocks (admin/build/blocks).
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauIf you’ve completed the gallery to this point, you’ve built an entire Drupal-based image gallery! However, there’s no need to stop here. One of the great things about building a site with Drupal is that you can continuously refine it, adding new features to any part of your site. This section details a few additional pieces of functionality that are common in photo-sharing websites:
- Community Tags (http://drupal.org/project/community_tags)
- Community tagging is just like the normal free tagging, except that it allows any guest (with permissions) to add tags to content, not just the original author. Enabling community tagging is very simple with the Community Tags module.
- Tagadelic (http://drupal.org/project/tagadelic)
- Community tagging and tag clouds are two things that go nicely together. Creating tag clouds in Drupal is very simple using the Tagadelic module. Tagadelic provides blocks that can display popular terms from various vocabularies in a weighted manner. More popular terms will appear as larger text in the cloud, such as in .
Figure : A sample tag cloud provided by the Tagadelic module- Taxonomy Redirect (http://drupal.org/project/taxonomy_redirect)
- In the current Robinson Family Photo-Swap, the gallery pages are nicely set up in a flowing set of thumbnails, but the taxonomy term pages still show the plain listing of nodes. This means that all the work we put into the gallery view won’t show up when a user clicks a taxonomy term underneath a photo or in a tag cloud.The best approach to fix this is to use the Taxonomy Redirect module to make these links point to the new location at the path gallery instead of taxonomy/term. This way, all the taxonomy term links for these two vocabularies will go to the thumbnail view instead of the default listing provided by Taxonomy module.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauIn this chapter, we introduced the modules ImageCache, ImageField, and Custom Pagers. We set up a Photo content type and customized its output through a combination of ImageCache presets, views, and a custom pager. We have the option to enable community tagging, tag clouds, and make all taxonomy links use the gallery view instead of the default taxonomy listing.Here are the modules that we referenced in this chapter:
- Community Tags module: http://drupal.org/project/community_tags
- Content Construction Kit (CCK) module: http://drupal.org/project/cck
- Custom Pagers module: http://drupal.org/project/custom_pagers
- ImageCache module: http://drupal.org/project/imagecache
- ImageCache Actions module: http://drupal.org/project/imagecache_actions
- ImageField module: http://drupal.org/project/imagefield
- Tagadelic module: http://drupal.org/project/tagadelic
- Taxonomy Redirect module: http://drupal.org/project/taxonomy_redirect
- Token module: http://drupal.org/project/token
- Views module: http://drupal.org/project/views
These are some other resources that we referenced and community resources for learning more about the new concepts introduced in this chapter:- All CCK-related modules: http://drupal.org/project/Modules/category/88
- Clean URL support: http://drupal.org/node/15365
- Image working group: http://groups.drupal.org/image
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 8: Multilingual Sites
- InhaltsvorschauCreating a website with community content is great, but what if some or all of your community doesn’t read or write English? It’s a big world, and only about 6% of it speaks English as a native language. Multilingual sites allow you to reach out to your community and let them feel comfortable contributing. Having multiple languages is not as simple as having users post content in whichever language they like. There are other things to consider, like navigation, date formatting, and help text. And what about having the same post available in multiple languages, and easily navigating between them? Once you start thinking about it in detail, there is a lot of ground to cover. Luckily, Drupal core and a few contributed modules have done a lot of that hard work for us so we can concentrate on building our community and content.Two big concepts for multilingual sites are internationalization, often abbreviated i18n, and localization, often abbreviated l10n. Internationalization is the underlying structure that allows software to be adapted to different languages and localization is the process of actually translating the software for use by a specific locale. Localization is not necessarily limited to just translating text, but also encompasses changing things like date formats and currency.Drupal 6 has made great strides toward building a better internationalization system inside Drupal core that makes localization much easier. Core does not quite provide us with all of the tools we need to completely localize a site, but there are contributed modules ready to fill the gaps.This chapter introduces the following modules:
- Locale (core)
- Provides interface for translating and importing translations for user interface text
- Content Translation (core)
- Handles translation of user-generated content
- Internationalization (http://drupal.org/project/i18n)
- Allows other elements to be translated, such as menus, blocks, and taxonomy terms
- Localization Client (http://drupal.org/project/l10n_client)
- An easy-to-use frontend for Locale module
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- InhaltsvorschauOur client, Migratory Patterns, is an international group that reports on and discusses migratory birds. They need a website that will allow everyone to have forums to discuss their shared passion as well as keep a repository of shared knowledge. They would like the site to provide language-specific forums for discussion, and allow members to navigate the site in their preferred language. They will also need an online knowledge base where members can share useful information, and a way to post news about the site. Additionally, they want to allow nonforum content to be translated by group members who know more than one language, so they can all share the accumulated knowledge. They currently have members who speak three different languages—English, Dutch, and French—but they would like the ability to add more languages later as the group grows.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Implementation Notes
- InhaltsvorschauThough Drupal core’s default Story content type can easily be used to post news to the front page, other features of the client warrant some further discussion.There are contributed modules available that add integration between Drupal and other forum systems, such as phpBB, but Drupal itself comes with its own simple forum using the built-in Forum module. The Forum module uses regular Drupal core concepts such as taxonomy (for forum containers and forums themselves), nodes (for posts inside a forum), and comments (for replies), which makes it integrate seamlessly with the rest of the website, including Drupal’s translation features.Another core Drupal module, the Book module, provides the ability for multiple users to collaborate together in order to create a collection of documentation. Book pages are structured into one or more hierarchies, with previous, next, and up links generated automatically on each page. Each page also provides a “printer-friendly version,” which will create an unformatted page consisting of the content of the current page and any subpages for easy printing or downloading for offline reading.User interface is the text that is provided by Drupal, both in core and contributed modules. This includes things like form labels, help text, and navigation. Drupal core’s Locale module provides the framework that allows user interface translations. To get the bulk of our localization, we will download translation projects that will supply us with translations of the core user interface. As we add contributed modules, we’ll need to check whether they supply a module-specific translation. If not, we are not out of luck, because core also gives us the framework to add and update translations as needed within our site. The “Localization client” module uses this framework to add a nice, user-friendly frontend to make translating interface text a breeze.Locale does not cover every single aspect of user interface text though, so we will be using the excellent Internationalization (i18n) module to fill in the gaps. The Internationalization module provides us the tools to translate taxonomy, blocks, and certain site variables like the site name and mission statement. In addition to providing extra translation, it also helps us manage our multilingual content.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Spotlight: Core Internationalization Features
- InhaltsvorschauDrupal core comes with two modules to handle languages: Locale and Content translation. Locale works with the user interface text and gives you a nice set of tools that let you import existing translations, create or edit your own, or export your site’s translations for use on other sites. Content translation lets you create multiple versions of the same content in different languages and associates the translated versions together.Another really nice feature in Drupal 6 core is support for right-to-left (RTL) languages, such as Arabic or Hebrew. If a language is set as an RTL language, Drupal will automatically flip all of the text so that it reads in the proper direction, as seen with Hebrew in .
Figure : A right-to-left language pageLocale handles the translation files and language switching options on the site. Let’s break it down and look at what that means.Translations
A “translation” is simply a file or collection of files that follow a standardized format. Translation files that follow this format have a special file extension, .po, which stands for Portable Object. A .po file is a simple text file that identifies strings of text and a particular language’s translation of the strings. In Drupal, translations contain a list of all user interface strings in Drupal, along with their translated versions.Drupal translation projects that you can download from http://drupal.org/project/translations are specially organized and packed groups of .po files that will match the Drupal directory structure when uncompressed. These projects cover only Drupal core’s strings, meaning any user interface text that is contained in the core Drupal download. An important thing to note about the translation projects is that they may be in various states of completion and sometimes you may not agree with the way something was translated. Not to worry; we’ll show you how to deal with that, too.In addition to the core translation projects, contributed modules may have translation files available as well. These would be contained in the module download, if they exist. The coverage for module translations is not very thorough, and as modules can be updated much more frequently than Drupal’s core translations, can become outdated quickly.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Installing a Translation
- InhaltsvorschauThe first step to using any of Drupal’s multilingual features is installing a translation, so that Drupal has more than one language to choose from. This involves two parts: downloading a translation and extracting it correctly, and configuring the Locale module to recognize it:
Figure : Translation download in the Drupal root directory- Begin by downloading a translation from http://drupal.org/project/translations, such as http://drupal.org/project/nl. As with modules and themes, ensure that you are downloading versions that match your version of Drupal.If you’re an advanced user accustomed to checking out Drupal code from CVS, you should be aware that for translations, you must download the translation and not use a checkout from CVS directly. The correct file structure for the translation files is created in the packaging process, and a CVS checkout won’t work without recreating that structure manually.
- Uncompress (unzip) the translation file in your Drupal root directory (that is, where index.php lives), as seen in .After uncompressing the file, the only change you should see in your root directory is the addition of new files that have the language code added (such as LICENSE.nl.txt.) If you see a new folder in your Drupal root with the language code (such as nl-6.x-1.0), then it did not install correctly. To double-check that the translation files were placed properly, you can look in the profiles/default directory—you should see a new translations folder with a language file inside (like nl.po), as seen in .
- Go to Administer→Site building→Modules (admin/build/modules), enable the Locale module and click the “Save configuration” button. Note that if you installed Drupal in a language other than English, this step will already be done for you.
- Go to Administer→User management→Permissions (admin/user/permissions), and configure the permissions as shown in . Save your changes with the “Save permissions” button.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Configuring Locale Features
- InhaltsvorschauNow we need to make a choice about how and when Drupal will use our new languages. To make it easy to see our site in different languages and allow our users to pick as they like, we will also add a simple language switcher to the site.As discussed earlier in the “Language switching” section, we have several options to choose from. We don’t want our users to have to manually switch their language in the account settings (the None option), and our client does not have separate domain names for each language (the “Domain name only” option). That leaves us with the two “Path prefix” choices. We are going to use the “Path prefix with language” fallback rather than the “Path prefix only” option, because our client wants to make sure that if a registered user has chosen a language in her account settings, she gets returned to that rather than the site default, should the prefix method not return a usable result:
- Click the Configure tab on the Languages page (admin/settings/language/).
- Select the radio button for “Path prefix with language fallback” and then click the “Save settings” button.
The Locale module provides a block to switch languages, which can be configured just like any other block to have a different (or no) title, and have various display options set.- Go to Administer→Site building→Blocks (admin/build/block) and find the “Language switcher” block in the list.
- Drag the block into the “Rightt sidebar” region, and then click the “Save blocks” button.
- You should now see a new block called “Languages,” which contains a list of each installed language on the site, as shown in .
Figure : Site with the language switcher block enabledEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Translatable Content
- Inhaltsvorschauan configure multilingual support for each content type (including any custom content types) that we have. We have three content types on our site: book pages, forum topics, and stories. We want stories and books to be translatable, but for forum topics we only need to identify the language, we don’t need translations created. We also want to make sure that all of our authenticated users have the permissions needed to add translations.
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Core – optional package
- Book
- Content translation
- Then go to Administer→Content management→Content types (admin/content/types) and click the “edit” link for the Book page type.
- Scroll down the screen and expand the Workflow settings section. You will see several options for Multilingual support. Select the “Enabled, with translation” radio button, as seen in , and click the “Save content type” button. This lets us identify the language for each piece of content, and in addition will let us create translated versions of the content that will be linked together automatically.
Figure : Multilingual support options for content types- Repeat for the Story content type.
- For the Forum type, select the plain Enabled option.
- We want all users to be able to translate content for us, so we need to make sure we set the permissions for everyone but anonymous users. Because all users are authenticated, we can do this by enabling the permission for all authenticated users. Go to Administer→User management→Permissions (admin/user/permissions), configure the permissions shown in , and click “Save permissions.”
Table : Content translation module permissions Permission: translation moduleanonymous userauthenticated usereditoradministratortranslate content
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Localization Client
- InhaltsvorschauYou may notice that even though you are using a translation that you have installed, there might still be some untranslated text peeking out here and there. This will become more likely as you add contributed modules. Almost no site will have absolutely 100% language coverage out of the box, so you will probably need to translate a few items yourself. Drupal has a built-in system to do this using the Locale module, but using it can be clunky and tedious. This is where the contributed “Localization client” module really shines. It makes quick fixes to text easy and intuitive.The Localization client adds a translation editor right on the bottom of your screen that stays with you as you move through the site. You can minimize it when you don’t need it and then expand it when you have translations to do. shows the editor expanded on a page. It provides a nice, easy-to-use interface to see which strings on the page have been translated and, more importantly, which have not. It allows you to browse or search through the list; you can simply select the string you wish and add the translation right there on the screen.
Figure : The Localization client interfaceSome important caveats should be kept in mind, however. The Localization client is a great tool but it does depend on JavaScript and, at the time of this writing, it does not assist with translating strings that are added by the Internationalization module (which we’ll discuss later). Additionally, it can only translate text that can be seen by the person running the Localization client; for example, if the text is visible only under certain conditions, it may not be translatable with the Localization client.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Translating the Interface
- InhaltsvorschauNot everyone wants or needs to install yet another module, and due to the caveats we mentioned about the Localization client, it is still a good idea to be familiar with how core translation works, so let’s start there.Interface translation depends on the Locale module, which should already be enabled on your site once you have installed a translation.
- Go to Administer→Site building→Translate interface (admin/build/translate) to get started.
- You will be presented with a table of your languages and the percentage of strings that have been translated so far. Click on the Search tab (admin/build/translate/search).
- The string search screen, pictured in , allows you to search for a specific piece of text somewhere in Drupal’s interface and translate it on the spot.
Figure : Translate interface string search screen- Enter the string multilingual support in the search box, leave the rest of the settings at their defaults, and click Search.There are two caveats to successfully finding a string to translate. First, the search interface is case-sensitive. Searching for “User” will return different results than searching for “user.” Second, the page with a given string on it must have been visited after the Locale module was enabled, or Search will be unable to find any of its interface text.
- On the search results page, pictured in , you will see a list of all the places on the site where that string is seen. The translation status is in the Languages column, which lists the language codes. A strike through a language code means it is not translated yet. Here, searching returned several results, which are all .
- Click the “edit” link next to one of the strings, which will bring you to the translation page, as shown in . You will be presented with a text area for each language, where you can add or edit the text as appropriate. When you click the “Save translations” button, the strings will be updated.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Translating Content
- InhaltsvorschauNow we need to set up our Knowledge Base section of the site. We’ll create some new content and then show you how to translate it.Earlier, we enabled translation for our pages, so let’s walk through the translation process itself:
- Make the Introduction to the Knowledge Base in English. Go to Create →Book page, fill in the fields as shown in , and click Save.
Table : Book page content FieldValueTitleIntroductionMenu settings- Menu link
Knowledge Base- Parent item
<Primary Links>- Language
EnglishBodyThis knowledge base is a place to organize useful information. Anyone with a Migratory Patterns account can add to this book! You may create a new page by clicking the “Add child page” link at the bottom of any existing KB page or by going to Create content→Book page in your navigation block.Book outline- Book<create a new book>
- After you save the content, you will see that there is a Translate tab next to the normal View, Edit, and Outline (for book content) tabs. Click the Translate tab and you will be presented with a table listing all of your site’s enabled languages, which you can see in .
Figure : The Translate tab on a book page, showing available languages and translation status- Click “Add translation” for a language, and you will be presented with a screen containing the form values that were previously submitted. You may now edit the text for the Title, Menu, and Body. Notice the language is already selected for you. Translate the text into the selected language, and remember to again choose “< a new book>” in the “Book outline” section as well so that this translated introduction page will also be a top-level book entry for those viewing the site in this language.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Internationalization
- InhaltsvorschauSo far we’ve got a nice start with getting our site translated, but everything is not quite smooth yet. We have translations for some of our content and menu items, but they are all appearing at the same time. There are multiple posts on the front page, and all the language menu items are showing regardless of which language we are viewing the site in. You will also see some stray text still in English. For example, under the “Create content” menu item, the content type descriptions are translated but the name of the content type is not. To take our multilingual site further and really make it shine, we are going to turn to a package of modules called Internationalization (i18n). There is a central Internationalization module, which comes packaged with a handful of other modules designed to work together to extend core’s multilingual features.One important thing that these modules do is help us get various strings of text into core’s translation interface that are otherwise not available. Drupal’s core interface tools can detect only strings that are hardcoded directly into the code (using Drupal’s
t()function); that is to say, that are code-generated. All of the user-generated strings are not accessible. It is important to realize that these strings that are added by the Internationalization modules will not be available to you through the Localization Client’s “Translate Text” interface. To translate these, you must use the core interface, covered earlier in this chapter in the ” section, found at →Site building→Translate interface (admin/build/translate).A second feature of many of these modules is adding a way to select a language for an item, such as for menus, blocks, or taxonomy terms, like the one shown in . Being able to discretely identify the language being used for an item allows the Internationalization module to filter the display based on the languages we want to see, leading to less duplication and confusion.
Figure : A language selectorEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Internationalization Features
- InhaltsvorschauTranslated content is all shown by default. The main Internationalization module will let you display only content that is relevant to the language currently in use:
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following module:
- Multilanguage – i18n package
- Internationalization
- Go to Administer→User management→Roles (admin/user/roles).
- Next to site administrator user, click “edit permissions,” and under i18n module, check the “administer all languages” permission, and save the form.
- Go to Administer→Site configuration→Multilingual system (admin/settings/i18n), where you will see the options for “Content selection.” By default it is set to “Only current language and no language.” Make sure that this option is selected and save the configuration.
If you go to the front page of the site, you will see that we now only get one “Welcome” post and one “Knowledge Base” menu item. If we choose Nederlands from the Language switcher block, you will see that the Dutch “Welkom” post appears, and the menu items change to the Dutch versions.Now the content we see is more streamlined, as shown in . Let’s move on to translating other items in the site that are being stubborn, such as the site name, Migratory Patterns.
Figure : With content selection mode enabled, we no longer see duplicate itemsBefore we can translate the various site-wide variables, we need to let Drupal know which ones we want to make translatable. To do this, we’ll need to edit the settings.php file:- In your Drupal installation, go to the sites/default folder.
- The settings.php file is currently read-only, so first change the permissions to make it writable. (This will vary by operating system. For example, on Linux systems, you set the permissions to 666 or a+w, and on Windows systems, you need to make sure that the Read-only checkbox is unchecked under the file properties.)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauWe’ve covered quite a bit of ground for setting up a site with multiple languages. There are a lot of tools available and therefore there is a lot of flexibility when it comes to handling languages. We have delivered to our clients a site that has the community features they need and allows their users to both participate in and manage the site in the language of their choice. They can easily add new languages to the mix in the future and everyone can help with translating their knowledge base. Here are some additional modules that can add some nice touches to your site:
- Language icons (http://drupal.org/project/languageicons)
- This module will add a default set of flag icons to the language switching links on the site (in the Language switcher block and language links on the content). You can replace the included icons with ones of your choosing.
- Translation Overview (http://drupal.org/project/translation_overview)
- This module creates a page with a table that tracks the translation status of all the content on your site. It supplies basic information like the title and a link to the content, content type, and creation date. Then, for each piece of content, it uses a legend so you can see the translation status (original language, current translation, out-of-date translation or untranslated) at a glance.
- Auto Timezone (http://drupal.org/project/autotimezone)
- Users can set their preferred time zone under My Account so that dates and times of content on the site are displayed in their local time. This module will enable this feature automatically for them based on the browser settings.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauWe built a nice, simple, easy-to-use site for our client that gave them the tools they needed for discussions and a knowledge base. We set up a forum that displays only posts that are in the user’s language and a knowledge base book that all of the site members can create translations for. The major need for this community was being able to use multiple languages and easily extend those languages in the future. Using Drupal’s core internationalization features with a handful of contributed modules, we have given them a very flexible multilingual solution.For more information and discussion about internationalization in Drupal, see the Internationalization group at http://groups.drupal.org/i18n. To get more information about core Drupal translations and how you can help, check out the Translations group at http://groups.drupal.org/translations. If you’d like to help the project by providing your own translations for Drupal core or contributed modules, the translator’s guide at http://drupal.org/contribute/translations has all the information you need.Here are the modules that we referenced in this chapter:
- Auto Timezone: http://drupal.org/project/autotimezone
- Content Translation: Part of the Drupal core
- Devel module: http://drupal.org/project/devel
- Internationalization and Language Icons: http://drupal.org/project/i18n
- Locale: Part of the Drupal core
- Localization client: http://drupal.org/project/l10n_client
- String Overrides: http://drupal.org/project/stringoverrides
- Translation Overview: http://drupal.org/project/translation_overview
These are some other resources that we referenced and community resources for learning more about the new concepts introduced in this chapter:- Drupal core translations: http://drupal.org/project/translations
- Multilingual modules: http://drupal.org/project/Modules/category/97
- Multilingual variables: http://drupal.org/node/313272
- Translations working group: http://groups.drupal.org/translations
- Translator’s guide: http://drupal.org/contribute/translations
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 9: Event Management
- InhaltsvorschauManaging online calendars and event registration can present a huge challenge. Without a dynamic system, the task is nearly impossible. Generating the HTML required to display a calendar and all the various presentation options (day, week, month views, and so on) is unreasonable; and worse, because the events are time-sensitive, remembering to update “next” or “upcoming” event lists can be onerous. Nothing looks worse than having last week’s meeting listed first on your “Upcoming Events” page.Even with dynamic systems, you tend to be constrained to certain parameters with fixed options. However, by taking advantage of the flexibility of Drupal and building on the powerful base of CCK and Views, you can accommodate nearly any variation on event listings for your site.To follow along with the hands-on example in this chapter, you should install Drupal using the Events install profile. The completed website will look as pictured in and at http://events.usingdrupal.com. For more information on using the book’s sample code, see the Preface.This chapter introduces the following modules:
- Date (http://drupal.org/project/date)
- Provides a CCK field for entering date information, as well as libraries to handle things like time zone conversion
- Calendar (http://drupal.org/project/calendar)
- A view style for displaying a list of site content in a rich calendar display
- Flag (http://drupal.org/project/flag)
- A flexible module that enables administrators to add on/off toggle switches to items such as nodes and comments
Figure : The completed Aurora Book Club siteThe Aurora Book Club is a rather social group of local book enthusiasts. They hold semiregular monthly meetings and events for both current and prospective members. Members want to be able to see when and where the next meeting is happening. Additionally, members should be allowed to post their own events to the site. Events should have start and end times and dates, as well as information about the event and where it will take place. To make it easy to see what is happening soon, there should be a short list of upcoming events in addition to the full calendar. The calendar needs to offer day, month, and annual views, and a way for members to subscribe to the club’s calendar using Microsoft Outlook or Apple’s iCal. Finally, since they would like to know how many cookies to bring and how many chairs to have on hand, the club president has asked that we include a way to track who plans to attend each event.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- InhaltsvorschauThe Aurora Book Club is a rather social group of local book enthusiasts. They hold semiregular monthly meetings and events for both current and prospective members. Members want to be able to see when and where the next meeting is happening. Additionally, members should be allowed to post their own events to the site. Events should have start and end times and dates, as well as information about the event and where it will take place. To make it easy to see what is happening soon, there should be a short list of upcoming events in addition to the full calendar. The calendar needs to offer day, month, and annual views, and a way for members to subscribe to the club’s calendar using Microsoft Outlook or Apple’s iCal. Finally, since they would like to know how many cookies to bring and how many chairs to have on hand, the club president has asked that we include a way to track who plans to attend each event.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Implementation Notes
- InhaltsvorschauThe book club has two main options for managing event data in Drupal. The options are indicative of a common trend amongst Drupal’s contributed modules. Specifically, there is a long-standing module in the Drupal community simply called Event (http://drupal.org/project/event), which natively handles most of the required features. The other option, and the one we will be using in this chapter, is a combination of CCK and Views add-ons: the Date module (http://drupal.org/project/date) and the Calendar module (http://drupal.org/project/calendar), respectively. The main differences are as follows:
- The Event module allows per-content-type “event enabling,” which means that it will add a start and end time to any existing content type. Included with the module is also an entire system for viewing your created events and even a block for listing upcoming events.
- The Date module offers a CCK field type for handling dates. The Calendar module is a Views plug-in that renders a view in a browsable calendar layout.
Both options are capable of meeting all the requirements for the book club’s site. In fact, when compared side by side, they look functionally equivalent: both options allow us to create new events, view a list of upcoming events, and offer rich, full-featured calendar displays. In fact, by working with any content type, the Event module still allows us to use CCK to build custom content types for our event data (for example, for holding additional information about events). This significantly blurs the line between the solutions, particularly compared to the choice between the Image module and Imagefield, as discussed in . With the Image module, a specific content type (“image”) is defined, whereas with Event you can reuse any custom content type. Furthermore, Event is a single module without any dependencies, whereas Date and Calendar require CCK and Views respectively. So why not use the Event module?Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: First Steps
- InhaltsvorschauFirst, we’ll set up a few basics for our site just using Drupal core and CCK. The main thing that we need in order to start off is a content type to handle our events. Log in to the Aurora Book Club site with the username admin, password oreilly, if you are using the installation profile.We’ll start by creating a new, basic content type just for events. We just need the event name and description along with an easy way to add the event location:
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- CCK package
- Content
- Text
- Go to Administer→Content management→Content types (admin/content/types) and select the “Add content type” tab (admin/content/types/add) to create a new content type called Event, using the settings from .
Table : Settings for the Event content type FieldValueIdentificationNameEventTypeeventDescriptionA book club meeting or social eventSubmission form settingsTitle field labelNameBody field labelDescriptionWorkflow settingsDefault optionsUncheck “Promoted to the front page”Comment settingsDefault comment settingsDisabled
- Click the “Save content type” button.
- Add a text field for storing the location of the event (that is, where the event takes place). You should have been returned to the Content types administrative page (admin/content/types) after saving the new type. Click the “manage fields” link for the Event content type (admin/content/node-type/event/fields). Complete the New field form using the values from .
Table : Settings for adding a location field to the Event content type FieldValueLabelLocationField namelocationSelect a field typeTextSelect a widget
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Date Module
- InhaltsvorschauThe main building block for the site is our new Event content type. The information that we need it to provide us with is “where” and “when.” We have taken care of the “where” part in our initial setup. The Date module helps us effectively answer the “when” question, in an incredibly flexible manner.As mentioned previously, our real interest in the Date module is to add a CCK field to our Event content type to indicate date and time. However, looking at the Date module more closely, there are a few extra pieces worth noting.As its name would imply, the Date API module merely provides a set of library functions for date handling. These functions consist of things like converting between date formats, providing integration with modules such as Views, and even generating date input select boxes. Though covering the full extent of the API is outside the scope of this chapter, it is worth noting that the Date API module does not depend on CCK, but is required by both the Date and Calendar modules. In theory, any module in Drupal that performs any sort of date handling or manipulation could take advantage of this .For users running PHP4, the Date PHP4 module is required to emulate date manipulation functions introduced in PHP 5.2. This module can optionally make use of an external library for parsing additional dates: the ADOdb date library (http://phplens.com/phpeverywhere/adodb_date_library). Without this library, Date PHP4 primarily handles dates from 1970 to 2038. The library adds support for any date from the year 100 to 3000. For the purpose of the book club, we will be able to just use Date API on its own.Drupal core, by default, does all time zone handling based on an offset from Greenwich Mean Time (GMT), represented as the number of hours’ difference (plus or minus) from GMT. For example, the offset −0400 is used for Eastern Daylight Time in the United States. This approach has several drawbacks, the most significant of which is in trying to account for Daylight Saving Time, as the offset will change. When the local time changes to Eastern Standard Time, the actual offset from GMT changes from −0400 to −0500, and the setting must be updated again.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Hands-On: Adding Dates
- InhaltsvorschauIn this section, we will transform our basic Event content type by adding the date component. This will be the linchpin of the book club’s site, as the rest of the site will build from this content.
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules (note that if you are using PHP 4, you will need to enable Date PHP4 as well):
- Date/Time package
- Date
- Date API
- Date Popup
- Date Timezone
- Go to Administer→Site configuration→Date and Time (admin/settings/date-time) and select an option from the “Default time zone” drop-down list that matches your time zone. Click “Save configuration” to save your changes.
With all our required modules enabled and set up, we can now customize the Event content type we created earlier by adding dates. Note that as we do this, we will only add a single CCK field to handle both the event’s start and end times:- Go to Administer→Content management→Content types (admin/content/types) and click the “manage fields” link for the Event content type (admin/content/node-type/event/fields). Complete the New field form with the values in .
Table : Settings for adding a time field to the Event content type FieldValueLabelTimeField nametimeSelect a field typeDatetimeSelect a widgetText field with jQuery pop-up calendar
- Click Save. This brings us to the date field configuration screen. As the Date module is geared toward event management by default, several of the default settings work well. Enter the values in , and click the “Save field settings” button to complete adding the configuration.
Table : Date field configuration settings FieldValueEvent settingsDefault valueNowInput formatSelect a format such as 08/29/2008−11:31pm
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Upcoming Events View
- InhaltsvorschauNow that we’ve created our event content type and started populating some content, it’s clear that we need to add in a way to access all our event data. In the book club’s requirements, we had a need for an “upcoming events” listing that would allow members to quickly see the meetings happening in the coming days or weeks. To achieve this, we will use the Views module to create our block. Keep in mind that when building views of event data, we generally want to do our sorting or our limiting on the date field, not the content’s created or updated time, as we normally do.We will create a simple block view of published events where the event’s time field is in the future. In terms of the views configuration, having a date value “greater than now” represents dates “in the future.” Finally, the view will be sorted in chronological (or ascending) order of the event’s date (not the event posting’s created date). When completed, this section will look as pictured in . Clicking the event name link in the block will take you to the full information.
Figure : The Aurora Book Club site showing a list of upcoming events- Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Other package
- Advanced help
- Views package
- Views
- Views UI
- Once the modules are enabled, go to Administer→Site building→Views (admin/build/views) and click on the Add tab (admin/build/views/add).
- Fill out the view form using the values in .
Table : The Upcoming Events view configuration values View settingValueView nameupcoming_eventsView descriptionA block list of upcoming eventsView tageventView typeNode
- Clicking the Next button places us in the main Views interface. From here, we can configure our view. Let’s begin with the Basic settings for the Defaults in , clicking Update after setting each one.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Calendar Module
- InhaltsvorschauAlthough a simple list of upcoming events is very useful (particularly in a sidebar block), the book club has additional requirements for the display of the event data. As is extremely common for event management websites, this site needs an interactive calendar for browsing through past and future events. We will implement this feature using the Calendar module in conjunction with Views.In addition to creating a nice online calendar, the Calendar module can handle the need for book club members to be able to update their desktop calendars (in Microsoft Outlook or Apple’s iCal) with the event information from the book club site. To do this, the desktop applications use a standardized format known as iCalendar (http://en.wikipedia.org/wiki/iCalendar), or iCal for short. Calendar comes with the Calendar iCal module, which allows us to easily provide this format for the interested members.The Calendar module provides a new view type that shows the results of a view in a calendar rather than a list or table as with the default view types. This view type is one of the more complicated ones available. It provides full day, week, month, and year views of the event data on our site with lots of links between views and paging through days, months, and years. To achieve this rich functionality, Calendar requires certain views arguments to exist, and to be ordered and configured in a certain way.The Calendar view type then determines which view the user would like to see based on the arguments that exist. For example, if our view URL is calendar, the Calendar view will handle the paths described in .
Table : Calendar path-based display PathCalendar displaycalendarMonth view, defaulting to the current monthcalendar/1970Year view, for the year 1970calendar/1970-1Month view for January 1970calendar/1970-1-1Day view for January 1, 1970Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Calendar View
- InhaltsvorschauIn this section, we’ll be enabling the Calendar view of book club events. Although this is potentially a daunting task, the Calendar module conveniently comes with a default view that handles most of the difficult bits for us. In this section, we’ll alter that default calendar view to fit our requirements.shows the finished Aurora Book Club calendar. Note the small iCal icon in the bottom right. Clicking this link will download the calendar to an appropriate desktop application.
Figure : Completed event calendar, with iCal link- Go to Administer→Site building→Modules (admin/build/module) and enable the following modules:
- Date/Time package
- Calendar
- Calendar iCal
- Go to Administer→Site building→Views (admin/build/views). You should now see “Default Node view: calendar” listed. Turn it on via its Enable link (admin/build/views/enable/calendar).
- Click its Edit (admin/build/views/edit/calendar) link to open the calendar view for editing.
- We need to make changes to the default Arguments. By default, the calendar view uses the date the node was last changed to place events on the calendar. Down in the Date field(s) section, click on the “Date: Date” link and under “Date field(s),” uncheck “Node: Updated date” and check “Content: Time (field_time value)” instead. Then click Update.
- For the Fields section, add the Content: Time (field_time_value) field, then make the changes noted in and click Update. This selection will show our event’s date, rather than the node’s last updated date, and will remove the word “Title” from the event name that comes by default.
Table : Calendar view fields configuration Defaults: FieldsValueNode: Updated date(Remove this field)Content: Time (field_time_value)Label: NoneNode: TitleLabel: (make this blank)
- We need to add some filters so that only our published Event content shows in the calendar. Do this by clicking the
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Flag Module
- InhaltsvorschauThe Flag module (formerly known as Views Bookmark) is an incredibly flexible module that allows you to create relationships between users and content on your site. After creating a flag, an item can be marked with the flag a few different ways, including links displayed below content, as shown in , or checkboxes displayed on the edit form, as shown in .
Figure : Flags as links shown on content
Figure : Flags as checkboxes shown on the node edit formUpon installation, the Flag module defines a “bookmark” relationship, allowing users to maintain a list of bookmarks (or posts they find interesting) on the site. However, this default behavior only touches on the surface of the flexibility of the Flag module. Some possible uses for Flag include:- A “favorite” or “bookmark” flag to mark content
- A “promote” flag (or many different promote flags) that are similar to the default “Promote to Frontpage” checkbox
- An “offensive” flag for comments and nodes
- A “friend” flag that allows users to mark other users as friends
- An “attending” flag for events
As you can see, there are a variety of uses for flagging content. After creating a flag for some purpose, views can be constructed that create lists of content that has been flagged by users. We’ll use it to let users indicate whether they plan to attend a book club event. Once the flag relationships are created, we can create a view to list the attendees of a particular event.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Flag Configuration
- InhaltsvorschauIn this section, we will configure the Flag module to allow our users to indicate that they are attending our events, as pictured in .
Figure : Attendance indicator shown on node the form- Go to Administer→Site building→Modules (admin/build/modules) and enable the “Other package: Flag” module.
- Now go to Administer→Site building→Flags (admin/build/flags) to manage the defined flags. By default, the Flag module defines a “Bookmarks” flag when installed. We can either add a new flag or edit the default one to suit our purpose. As we won’t be using “Bookmarks” on this site, we’re going to edit the default. Click the “edit” link next to the bookmark flag (admin/build/flags/edit/bookmarks). Fill out the form according to .
Table : Attendance flag configuration FieldValueNameattendanceTitleAttendanceFlag link textattend this eventFlag link descriptionAttend this eventFlagged messageYou are attending this eventUnflag link textcancel attendanceUnflag link descriptionCancel attendance to this eventUnflagged messageYou are no longer attending this eventWhat nodes this flag may be used onEvent: CheckedStory: UncheckedDisplay optionsDisplay link on node teaser: UncheckedDisplay link on node page: CheckedDisplay checkbox on node edit form: Unchecked
- Clicking Submit will create our attendance flag. We can now go to any events that we previously created and click the “attend this event” link.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Attendee View
- InhaltsvorschauThe Flag module provides a default view that will allow any user to see the content that she has flagged for any flag that we have defined. You should now see a My Attendance link in the Navigation menu, which will show all of the events that you have marked as attending.However, the book club would also like to see a list of who will be attending each event. For this, we will need to create a new view, pictured in .
Figure : Event attendees list view- Go to Administer→Site building→Views (admin/build/views) and click on the Add tab.
- Complete the form according to .
Table : Attendees view settings SettingValueView nameattendeesView descriptionAttendees for a given eventView tageventView typeUser
- The first thing we need is a relationship to give us access to the flag information related to our users in our view. Click the
+(plus) sign in the Relationships section and check the “Flags: User’s flagged content” relationship and click Add. Complete the relationship settings based on .Table : Settings for the Flags relationship Defaults: RelationshipValueFlags: UserLabel: attendanceInclude only users who have flagged content: CheckedFlagged: Attendance
- We want our view to show the users who have flagged a given Event node; therefore, we need to add an argument for the Node ID that was flagged. To do this, we click the
+(plus) sign next to Arguments. Check the “Flags: Content ID” argument and click Add. The default values for the argument are fine, so we can click Update. - Now we can add the fields that we want to display. Click the
+(plus) icon next to Fields. Check the “User: Name” field and then click Add. Blank out the Label text so that there is nothing there and click Update.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauThe site we have built covers all of the needs for the club. As they go down the road, the members may want to spruce things up a bit. Here are a few modules that could round out the site even more:
- Calendar Popup (part of the Calendar module)
- The Calendar package also includes this module. This will make it so that when you click on an event in a calendar display, it will appear as a JavaScript pop-up rather than taking you to the node page. This is handy if you want people to be able to browse the details of events without leaving the calendar view page.
- Countdown (http:drupal.org/project/countdown/)
- This module adds a block that shows the time left until an event. This is a nice way to let people quickly know that the next meeting is in four days or four hours.
- Flag Actions (part of the Flag module)
- The Flag module can be set up to send emails, and to unpublish or delete nodes upon reaching certain flagging thresholds. Although this feature is most commonly used for things like community flagging of spam or offensive content, it can also be used to notify someone by email if, say, more than 10 people will be coming to an event and a second person needs to be asked to help supply refreshments.
- Location (http://drupal.org/project/location/) and GMap (http://drupal.org/project/gmap/)
- Instead of just typing a location in a text field, you can use the Location and GMap modules to let people use a Google map to select the location for each event.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauIn this chapter, we have looked at building an event management site for the Aurora Book Club, making use of the Date field for CCK, the Calendar plug-in for Views, and the Flag module for handling attendance. The book club now has a handy calendar for display on the site, as well as being available in iCal format. They also have an easy-to-find list of all the attendees. The site is simple and easy to use, yet fits all of the club’s needs quite nicely.Here are all the modules we referenced in this chapter:
- Calendar: http://drupal.org/project/calendar
- Countdown: http://drupal.org/project/countdown
- Location: http://drupal.org/project/location
- Signup: http://drupal.org/project/signup
Additional resources:- ADOdb Date Time Library: http://phplens.com/phpeverywhere/adodb_date_library
- Date module handbook: http://drupal.org/node/92460
- Event-related modules: http://drupal.org/project/Modules/category/61
- iCalendar: http://en.wikipedia.org/wiki/ICalendar
- PHP date formatting: http://php.net/date
- PHP strtotime:http://www.php.net/manual/en/function.strtotime.php
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 10: Online Store
- InhaltsvorschauMany businesses both large and small would like to take better advantage of their web presence by selling their products or services directly online. Setting up e-commerce, however, can be a very daunting task. There are several options with varying complexity. Many hosting providers offer e-commerce or “shopping cart” packages that may be either included with your web hosting plan or available for purchase. Other services, such as PayPal, offer simple ways of including means for simple purchases using an HTML form that submits to their processing system. There are other options still for using dedicated e-commerce packages, both open source and proprietary, that you host and configure. The biggest issue with all of these methods tends to be the lack of integration with the rest of the website—all shopping cart functions and checkout take place within the other, external system.The other complication with e-commerce implementations is that there is real money involved for both you and your customers. Customers will be providing credit card details and other sensitive information, so we need to be aware of security implications.This chapter will introduce the following module:
- Ubercart (http://drupal.org/project/ubercart)
- Provides a full e-commerce package for running an online store
To follow along with the hands-on example in this chapter, install Drupal using the Online Store install profile, which installs Drupal with a few sample users and basic settings, as shown in and found at http://store.usingdrupal.com. For more information on using the book’s sample code, see the Preface.
Figure : Sweet Tees’ completed websiteSweet Tees is a local T-shirt store that sells wildly popular, custom-printed T-shirts. They have a physical storefront, and the owners enjoy running a small store and love their current location. However, they get frequent mail order requests for their shirts and stickers, and would like to grow that end of the business. Taking orders on the phone and tracking sales has proven to be inefficient and time-consuming for both them and their customers.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Case Study
- InhaltsvorschauSweet Tees is a local T-shirt store that sells wildly popular, custom-printed T-shirts. They have a physical storefront, and the owners enjoy running a small store and love their current location. However, they get frequent mail order requests for their shirts and stickers, and would like to grow that end of the business. Taking orders on the phone and tracking sales has proven to be inefficient and time-consuming for both them and their customers.In order to increase sales, we will equip the Sweet Tees website with an online store that has integrated shopping cart functionality, where visitors to the site can add items to their cart without the hassle of having to create an account first. A shopping cart should be visible on all pages with a link to “check out” at any time. The store needs to flow seamlessly with the existing website so that customers have a consistent experience. Sweet Tees would like to make the checkout process as simple as possible, so we will also need to make sure we provide them with a single-page checkout, without requiring customers to create a user account. Finally, they wish to accept credit cards on their orders, so we will need to set up a payment gateway for this purpose.Sweet Tees has several options to manage their online store; however, they really want to provide a seamless, user-friendly experience for their customers. They are looking for a solution that is simple and elegant, yet also comprehensive.For Drupal, there are two primary e-commerce solutions, both of which consist of several modules, to implement the various features required.The e-Commerce module (http://drupal.org/project/ecommerce) is the oldest and more flexible of the options. The package is designed to be a highly modular framework for building e-commerce solutions in Drupal. In a way, it is a development framework of its own on top of Drupal’s existing framework. The principal benefit of the e-Commerce package is ultimate control and extensibility. Because of the high number of variable components in an online store (payment processor, shipping calculations, taxes, and so on), this flexibility is incredibly useful. The downside, however, is that the flexibility increases the level of complexity, thus making it more time-consuming to set up and configure. Also, again due to its architecture, the checkout process for the e-Commerce package takes several pages and requires that customers register accounts on the website. This violates two of the client’s primary requirements.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Spotlight: Ubercart Packages
- InhaltsvorschauUbercart is a complete package for running an online store. As such, it actually contains more than 30 individual modules that implement each of the various features required for running an online store. These modules range from basic framework modules such as Payment or Cart to very specialized modules that implement specific features. Navigating the giant list of modules (which is more than Drupal core itself includes!) can be confusing, so in this section we’ll look at each module and outline its purpose and where it fits.The modules that make up the Ubercart package are broken into five packages under Administer→Site building→Modules (admin/build/modules). We’ll look at what the modules in each package include in this section.The Ubercart—core package represents the base framework components for our online store. There are five modules in this section: Cart, Conditional Actions, Order, Product, and Store. Each of these modules is required for running an online store. Following is a brief description of each:
- Cart handles the shopping cart, pictured in , with features such as tracking which products a customer has selected and the quantity of each product that has been ordered. The Cart module is also responsible for the “checkout” procedure. In addition to the basic functionality, the Cart module also provides options for extensibility in the shopping cart and checkout functions for other .
Figure : Shopping cart provided by the Cart module- Conditional Actions provides a mechanism for the rest of Ubercart to use for providing configurable, rules-based actions for things like taxes and shipping. This module makes use of the core Actions system and is an advanced alternative to the Trigger module in Drupal core, which was covered in .
- Order is responsible for recording, tracking, and managing individual orders to the store. shows an order generated by the Order module. The Order module provides features for manual, backend creation of orders (that is, those taken over the phone), and invoicing, as well as an interface for viewing and editing existing orders. Like the Cart module, Order also serves as a framework module for the rest of the package by providing hooks for automated fulfillment and payment processing.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Ubercart’s Administration Panel
- InhaltsvorschauUbercart, due largely to its complexity and vast number of modules, has its own administration section, which is found at Administer→Store administration (admin/store), as seen in . All subsequent Ubercart features will be managed under this new section.
Figure : The Ubercart administration panelThe main panel shows a listing of all available actions to perform on the store, and includes managing the product catalog, viewing and filling store orders, viewing reports on store activity, and adjusting the configuration of any setting. Additional sublinks of each section are hidden by default and expanded by clicking the “Show links” link. Below the main panel is a list of status messages that may indicate problems or missing configuration steps. It’s a good spot to check if things aren’t working correctly.The Orders, Customers, and Products links each point to a section where you can create, manage, and search existing records. This is where day-to-day store maintenance happens.The Reports section allows you to answer questions about how well the store’s performing overall. What products are selling well? Are there plenty of products in stock, or is it time to order more? How is the store’s bottom line? All of these questions and more can be answered with the tools available here.The Configuration section contains oodles and oodles of settings for everything from where users get redirected after they add something to their shopping cart, to what the input form looks like for entering a shipping address and how many orders should be displayed in the order overview form. If there’s a particular behavior of Ubercart you really wish you could change, chances are good that you’ll find it here. Unlike most Drupal administration sections, the “Store settings” section provides an outline that lists all the currently set values grouped in sections. To edit any of the values, just click on a section (which will highlight on mouseover), as seen in .
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Setting Up the Store
- InhaltsvorschauTo begin setting up the online T-shirt store, we must first establish some basic information about the store that later features will be able to use. Let’s get started with the essentials: the store information that will be used in invoices and to calculate shipping costs.
- Log in to the Sweet Tees site as the admin user if you have not done so already.
- Go to Administer→Site building→Modules (admin/build/modules) and enable the following module:
- Ubercart—core package
- Store
- Go to Administer→Store administration→Configuration→Store settings (admin/store/settings/store).
- Click on the “Name and contact information” section, which brings up the “Contact settings” form (admin/store/settings/store/edit). Complete this form as shown in , and click the “Save configuration” button when done. When you return to the “Store settings” Overview page, it should look as pictured in .
Table : Contact settings SettingValueStore nameSweet TeesStore ownerStephen SweetE-mail addressstore@example.comPhone number800-555-1234Fax number110-555-4321Street address 1123 Example StStreet address 2CityExample CityCountryUnited StatesZoneCaliforniaPostal code90210
Although Ubercart defaults to supporting North American conventions, these are all fully configurable. The “Format settings” tab (admin/store/settings/store/edit/format) allows us to configure the display of various measurements such as currency, weight, length, and dates. And under the Country settings form at Administer→Store administration→Country settings (admin/store/settings/countries), you can import additional country data and set up country-specific address forms.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Products, Product Classes, and Attributes
- InhaltsvorschauBefore we get to the next step—adding products to our store—it’s worth taking some time to discuss how Ubercart treats products within the system.Products in Ubercart are nodes, which means that you can do anything with products that we’ve done with nodes in the rest of this book: you can add comments or ratings, tag them, add CCK fields to hold additional properties, display products in listings with Views module, and so on. This seamless integration of store products with the rest of the content that Drupal can manage is a “killer” feature of Ubercart.Ubercart’s Product module defines a single “Product” node type, which comes prebuilt with fields such as SKU and sale price, as pictured in . These fields interact directly with other parts of the system, such as sales reports and shipping calculations.
Figure : Product information supplied by the Product moduleA single-product node type is sufficient if you are only selling one style of product in your store, such as a club membership. Many online stores are more complex, however. Amazon.com sells books, movies, and, as we saw in , kitchen utensils. Books have properties like “author” and “ISBN number,” and movies might have properties like “rating” and “movie studio.” Can you imagine how long the product node form would be if it needed to provide a field for every single one of these properties for all possible types of products? No thanks.Luckily, the Ubercart developers have a solution to this predicament: special node types called product classes. Product classes are slightly different than standard content types, as they need to inherit the base product fields. However, once a product class is created, it will then look and behave like a normal Drupal content type—there will be an entry form for it under “Create content” (node/add), and we can edit fields and properties via Administer→Content management→Content types (admin/content/types). Each product class may be customized without affecting other products. You can create a product class for “Book” and a product class for “Movie” and use CCK to give each its own specific properties. We’ll make use of product classes later on for creating our and sticker products.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Creating Products
- InhaltsvorschauIn this section, we will be setting up the product information for Sweet Tees, which is the first piece required to put together our online store. Ubercart’s Product module provides a Product content type for us on installation, and the FileField (http://drupal.org/project/filefield), ImageField (http://drupal.org/project/imagefield), and (http://drupal.org/project/imagecache) modules that we covered in will allow us to display and collect images on products.As Ubercart uses the ImageField and ImageCache modules for all product image handling, we can modify any of the default settings using the techniques outlined in to customize them for our purposes.Go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- CCK package
- Content
- FileField
- ImageField
- Core package
- Path
- ImageCache package
- ImageAPI
- ImageAPI GD2
- ImageCache
- ImageCache UI
- Other package
- Token
- Ubercart—core package
- Product
- Ubercart—core (optional) package
- Attribute
- Catalog
After enabling these modules, we can see that our store administration section has changed dramatically. Going to Administer→Store administration (admin/store) now shows messages in the “Status messages” list and two new sections, Products and Attributes, as seen in .
Figure : Store administration panel, after enabling Product-related modulesWhen we enabled the modules in the previous step, Ubercart automatically added a Product content type and associated it with an Image field so that we can attach pictures to our products. However, Sweet Tees sells two kinds of products: T-shirts and stickers. In order to accomplish this requirement, we’ll create two product classes, as shown in .
Figure : Product classes for T-shirts and stickers- Go to Administer→Store administration→Products→Manage classes (admin/store/products/classes).
- You will be presented with a form to add a class. Create the first class, for T-shirts, according to and click “Submit.”
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: The Ordering Process
- InhaltsvorschauWe now have an online store that can be populated with the entire Sweet Tees inventory. However, at the moment customers can only browse the catalog and see information about the products. Most e-commerce sites are concerned with actually selling something, and that means getting into the ordering process.depicts the typical workflow for a store such as our client’s. It begins when a customer adds products to her online shopping cart and clicks the “Checkout” button. The customer is presented with a form in which to fill out basic customer information, such as billing and shipping address, credit card information, and preferred shipping method. The customer then has a chance to review the order, including its total price, with taxes and shipping calculated based on the information provided earlier. Once the order is submitted, a payment gateway validates the entered billing information to determine if the credit card is legitimate. If all goes well, the order is placed and the store fulfills its end of the bargain by packing the products up and shipping them where they need to go.
Figure : Ubercart’s typical ordering processAlthough this is typical for a “traditional” e-commerce store, many types of stores have very different needs. Ubercart’s module suite allows for many flexible ways to configure a customized ordering process. Want to sell downloadable products, which have no need to be shipped anywhere? No problem. Turn on the Downloads module, and turn off the Shipping module. Need to calculate complex international tax rules? The Conditional Actions module combined with the Taxes module will do what you need. Does an order in your system take lots of steps on its way to being completed, such as “Pending various red-tape paperwork” or “Needs invoice”? The Orders module has the ability to define custom workflow states for your orders, so you always know the current state of open orders in the system.Although there are far too many configuration options to get into all of them in detail here, we’ll discuss some of the settings pages that impact ordering, found underneath Administer→Store administration→Configuration (admin/store/settings):Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Processing Orders
- InhaltsvorschauThe remaining element of our site is actually implementing the e-commerce portions: an online shopping cart and the ability to process orders, as well as reporting tools to tell us how our store is doing. We will now complete our store configuration.To complete this section, we must first enable one final set of modules. Go to Administer→Site building→Modules (admin/build/modules) and enable the following:
- Ubercart—core package
- Cart
- Conditional Actions
- Order
- Ubercart—core (optional) package
- Payment
- Reports
- Shipping
- Shipping Quotes
- Taxes
- Ubercart—fulfillment package
- Flatrate
- Ubercart—payment package
- Credit Card
- Payment Method Pack
- Test Gateway
Because the precise instructions for implementing payment systems vary widely between various services (Paypal, Authorize.net, and so on), in this chapter, we’ll be setting up credit cards only with a test gateway. On a “real” e-commerce site, you’ll want to use an actual payment gateway that can accept and process credit card transactions for you. Ubercart’s website contains a list of its supported payment systems, along with documentation on how to set them up: http://www.ubercart.org/payment.In this section, we will configure the site’s shopping cart, as pictured in . Once we get the cart set up, we will be able to browse to an individual T-shirt page, select options such as color and quantity, and add the customized products to our cart.
Figure : Ubercart’s shopping cart, along with a sidebar blockThe vast majority of our work for this section is completed by simply enabling the Cart module. The cart settings come with very workable defaults, but there are a couple settings we want to change:- Go to Administer→Store administration→Configuration→Cart settings (admin/store/settings/cart) and click the “Cart settings” section (admin/store/settings/cart/edit).
- The default setting for the “Continue shopping link URL” is to return the user to the site’s front page. We should change this to be the full catalog. Enter “catalog” and click “Save configuration.”
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauIn this chapter, we have covered the basics of setting up an online storefront and shopping cart using the Ubercart package for Drupal. However, there are several additional modules that you will likely want to consider before taking your online store live:
- Secure Pages (http://drupal.org/project/securepages)
- When collecting sensitive, personal information online—particularly credit card information—it is highly recommended that you do it via a secure, SSL connection. The Secure Pages module allows you to specify certain Drupal paths that should be visited only via HTTPS. The recommended paths to protect are user/* and
- PayPal (included with Ubercart)
- Although the PayPal module is not required, you will likely want to use some payment gateway for processing payments (recall that we used the Test Gateway in this chapter). PayPal’s merchant services are easy to set up and well supported by Ubercart.
- Stock (included with Ubercart)
- Particularly when selling something like T-shirts, it is a good idea to keep track of the current available stock level to avoid selling someone a product that is not available. The stock module (found in Ubercart—extra) updates a given stock level for each product every time a purchase is made. When new stock arrives, simply add the new quantity to the current level. Also included with the module is a threshold setting which, when reached, will trigger an email notification that inventory is getting low.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauIn this chapter, we were able to set up a complete online store for our customer, Sweet Tees. Although there are a lot of modules, configuration screens, and chances to override the features in Ubercart, the sane default options and helpers for common tasks such as setting up ImageCache presets make Ubercart fairly easy to get running.Here are the modules we referenced in this chapter:
- e-Commerce: http://drupal.org/project/ecommerce
- FileField: http://drupal.org/project/filefield
- Google Analytics: http://drupal.org/project/google_analytics
- ImageAPI: http://drupal.org/project/imageapi
- ImageCache: http://drupal.org/project/imagecache
- ImageField: http://drupal.org/project/imagefield
- Ubercart: http://drupal.org/project/ubercart
Here are the additional resources that we referenced in this chapter:- Ubercart official site: http://www.ubercart.org
- Ubercart contributions: http://www.ubercart.org/contrib
- Ubercart credit card security: http://www.ubercart.org/docs/user/2731/credit_card_settings#security
- Ubercart payment systems: http://www.ubercart.org/payment
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Chapter 11: Theming Your Site
- InhaltsvorschauThe rest of this book has extensively discussed how to construct a diverse array of websites from photo sharing to product reviews to event management by combining powerful Drupal core features and dozens of add-on contributed modules. Drupal gives you a lot of tools to move things around and arrange the functionality of your site, but often the main difference between most websites comes down to presentation.When you think about it, there’s really not much difference between the functionality of YouTube and Flickr. Certainly, one manages video content and the other focuses on photos. But these sites have more similarities than differences. Both manage media content and allow users to share their uploads. Both allow users to create a network of contacts. Users can create their own profiles, comment on others’ content, and mark content as a “favorite” for later reference.Functionally, these sites are very similar, but their presentation is completely different. The layout of the sites is different, their backgrounds are different, their entire look and feel is different—each has a different presentation of its elements.When we talk about theming, we are talking about Drupal’s presentational layer. It is where the site developer is able to take complete control and specify what goes onto the page. All CSS, JavaScript, images, and HTML can be rearranged and overridden by a Drupal theme. Drupal’s theme system can provide special formatting of the site for mobile devices, reformat content for display in RSS feeds, display a thumbnail of the user’s image whenever the username is shown, completely change the default output provided by a module, and much more. Drupal theming is a topic broad enough to fill an entire book of its own. The aim of this chapter is to give an overview with as many tip-of-the-iceberg concepts as possible—to show what can be done and some basic information on how to do it. We hope to give you enough of an overview so that if you are interested in customizing the look and feel of your Drupal site, you will be able to use the concepts in this chapter as a launching pad.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Spotlight: The Theme System
- InhaltsvorschauAs discussed briefly in , modules generate the contents of a given page, and the theme system provides the opportunity to cut in and customize the page before it’s displayed. A theme is a collection of images, CSS, and (usually) HTML/PHP files that change the look of Drupal’s default output. With a simple flick of a radio button, you can completely change the design of your website by choosing a different theme, and you can customize settings on a theme to make adjustments, such as to the site logo or colors, as we saw in .provides a general overview of how the theme system works. Each path in Drupal corresponds to a particular module that is responsible for handling the page request. For example, “node/1” is handled by the Node module, “admin/build/themes” is handled by the System module, and a path like “albums” might be handled by the Views module. After the module has built up the contents of the page, it calls up the theme system with a special function called
theme(), which we’ll be discussing in more depth later in the chapter.The theme system consists primarily of a theme engine, which defines the dynamic parts of the page, as well as the rules for how Drupal’s output is defined and can be overridden, and the currently enabled theme, such as Garland. The theme engine is capable of setting up the basic structure and markup of the content and rendering the entire page template with the current page’s content inside of it. But where the visual magic happens—and where you start to gain control over exactly how each element on the page looks—is in the theme itself.Every single element on the page, from the title in the browser window, to the site logo, to the regions where blocks are placed, to the links in the menu bar, is run through the theme system. The difference between an obviously “Drupal”-looking site and a stylish site is creative use of the tools provided by the theme layer. Let’s look at the pieces of a theme we have to work with, as well as how Drupal expects us to use them.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Creating a Custom Theme
- InhaltsvorschauLet’s look at how you can modify one of Drupal’s themes to make it your own. There are many good themes that can act as a good “starter theme.” The Drupal contributed themes repository (http://drupal.org/project/Themes) has several specifically designed for this purpose—the Zen theme (http://drupal.org/project/zen) is often recommended. For our example, we’ll start with a simple core theme: Bluemarine, as pictured in .
Figure : The Drupal core Bluemarine themeBluemarine was Drupal’s default theme prior to Drupal 5. It uses a table-based layout, which is generally considered bad practice in these days of CSS-based layout . However, for the purposes of our example, it makes for a simple and clean starter theme. Let’s see what we can do to customize it.shows the Bluemarine theme directory. It contains template override files for blocks, boxes, comments, nodes (all types), and the page. There are images for the default logo and a screenshot for the theme listing page. The required .info file is there. The main stylesheet for the theme is called style.css and there’s another sheet called style-rtl.css that gets called in when Drupal is displaying right-to-left languages such as Arabic or Hebrew.
Figure : Bluemarine theme filesThe first step in customizing a theme is to make a copy of it and place it into the appropriate location in the sites directory. Think of the sites directory as “the stuff that makes your site yours.” All of your customizations, installed modules, and themes should go into this directory. For most sites, this will mean placing themes into sites/all/themes. Drupal will discover themes within subdirectories, so feel free to organize this however you like.- Ensure that sites/all/themes exists and copy the bluemarine directory into it.
- Rename the new directory from bluemarine to newmarine.
- Rename the bluemarine.info file to newmarine.info.
- Open newmarine.info into a text editor and edit the file to reflect the new name. This is the information that will appear on the theme listing page in Drupal:
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Template Files
- InhaltsvorschauThe great thing about overriding the HTML in template files is how totally easy it is. All you have to do is find the default template file, copy it into your theme folder, and edit to your heart’s content. Many themes start with these main Drupal core default templates:
- page.tpl.php (located in modules/system)
- Controls the layout of the entire page. This isn’t for the page content type; you can think of it more as the overall screen in which your content types and blocks are displayed.
- node.tpl.php (located in modules/node)
- This is used for the display of each individual node.
- block.tpl.php (located in modules/system)
- This is used for all of the blocks on the site.
- comment.tpl.php (located in modules/comment)
- Each individual comment is displayed with this file.
- box.tpl.php (located in modules/system)
- This is a rarely used legacy template. It is used in Drupal core for the container element that surrounds search results and that surrounds a list of comments that is attached to a node.
Just like the node and comment template files, you can find any other templates in the folder of the module that created it. This holds true for core and contributed modules. So, for example, forum templates will be in the forum module folder (modules/forum) and templates for the calendar module will be in the calendar module folder (sites/all/modules/calendar).In addition to the basic template files provided by core, there are a number of additional “suggested” templates, such as page-front.tpl.php, which will affect only the layout of the home page of the site. It is also possible to theme content types differently based on using suggested templates. Perhaps blog posts show the author’s picture at the bottom, and stories and page posts do not display the picture at all. Content-type-specific templates use the naming scheme node-nodetype.tpl.php, where nodetype is “story,” “page,” “forum,” “blog,” or whatever the machine-readable name of your content type is. These machine-readable names can be found in the Type column of the Content types listing page at Administer→Content management→Content types (admin//types), as seen in .Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Working with Template Files
- InhaltsvorschauNow let’s look at customizing the page.tpl.php file. This is the file that defines the general HTML structure of the entire page. The theme engine and enabled modules make a number of variables available to this file, and then these variables are simply output using PHP print statements. Let’s change the structure of our theme by moving the breadcrumb output up into the header region of the page. We want our breadcrumbs to look like those shown in .
Figure : Breadcrumbs appearing in the headerThere are many variables available to the templates, and not all of them are used in the themes provided by Drupal core. A list of variables can be found at http://drupal.org/phptemplate, with the variables for each template listed under the appropriate section; however, modules can add and alter this list, so a better way to discover these variables is to use the Devel Themer module, which we’ll discuss in a moment.- We are going to use the Theme developer module to help us out, so go to Administer→Site building→Modules (admin/build/modules) and enable the following modules:
- Development package
- Devel
- Theme developer
- You should still be on the module administration page, which has a breadcrumb trail at the top. You will also notice that you have a new translucent box in the lower lefthand corner of your browser window with a Themer info checkbox as shown in . Check the box to turn the Theme developer module on for the page.If the theme developer tool isn’t working, PHP may have exceeded its memory limit. Try visiting a page other than the modules form, which requires a lot of memory to display, especially combined with the theme developer tool (which also takes up a lot of memory). Disable the theme developer tool when not using it.
Figure : The Themer info checkbox appears after enabling the Theme developer moduleEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Spotlight: Advanced Overrides
- InhaltsvorschauTo really get in and affect things in the dynamic realm, you will need to move away from HTML and CSS, and begin using PHP; only PHP can modify the deepest layers of Drupal. The following two sections discuss how to override variables and functions in the theme’s template.php file. You should have a basic understanding of what PHP variables and functions are in order to get the most out of this part of the chapter.There’s much more information available about these kinds of advanced overrides available in the Drupal 6 theming guide at http://drupal.org/node/173880.Those little bits of dynamic content that you are using in your template files are really handy—until they annoy you by not quite producing exactly the output that you want. The variables that Drupal creates by default, like
$site_nameand$submitted, are meant to be a baseline that will fit a lot of people’s needs. Like everything else in the theme system, though, you have the power to crack them open and change them. Not only can you override existing variables, but you can also create your own brand-new .All variables that go out to a template file are first passed through a special kind of function, called apreprocessfunction. You can add your ownpreprocessfunction to your template.php file and get the last shot at the variables before they head out to the template. To keep things tidy, you can use onepreprocessfunction per template; for example, you can create amytheme_preprocess_pagefunction to affect variables to be used in your page.tpl.php file. With this function, you can define, or redefine, any variable. For instance, if you wanted to make a new variable that printed out a random number between 1 and 100, you could add this to template.php:function mytheme_preprocess_page(&$vars) { $vars['random_number'] = rand(1, 100); }Then (after clearing the Drupal cache), you can print out that variable out in your page.tpl.php file just like any other variable:<?php print $random_number; ?>
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Hands-On: Using template.php for Overrides
- InhaltsvorschauDrupal gives us lots of nice variables to use, but they don’t always look the way we prefer. A common item that many people wish they could change is the “Submitted by...” line, which prints out the author name and date that a node was created. You can turn this display off and on in the theme configuration screen at Administer→Site building→Themes (admin/build/themes), under the Configure tab (admin/build/themes/settings), but you can’t change what information is actually printed out when the display is on. We’re going to change this line to instead print out “Posted on” followed by the date, as shown in .
Figure : Changing the text of the “Submitted by…” line to “Posted on…”One important piece that we need in order to modify this is a template.php file. As our Newmarine theme doesn’t have a template.php file in it yet, we’ll create that as well to accomplish our task:- If we go to a node that has submitted information showing and do the same Drupal Themer Information trick that we did back when we moved the
$breadcrumbvariable, we can find out what the parent template for that “Submitted by…” line is. You will see that its parent is the node.tpl.php file. If you open up that file (or node-story.tpl.php if you completed the hands-on example in the earlier section ”), we can see that the$submittedvariable is being printed there to produce that output as highlighted below (remember we just moved this line earlier, along with the taxonomy terms):<?php if ($page == 0) { ?><h2 class="title"><a href= "<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?> <div class="content"><?php print $content?></div> <span class="submitted"><?php print $submitted?></span> <div class="taxonomy"><?php print $terms?></div> - To change this, we can override it in our template.php file. But Newmarine doesn’t have a template.php file yet. So let’s create one and put it in our
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Taking It Further
- InhaltsvorschauA little bit of PHP knowledge can take you a long way. There is a whole section of the handbook at http://drupal.org/handbook/customization/snippets that contains handy bits of code that you can add to your site to accomplish various tasks. These are easy ways to tweak your site to be just the way you need it.Many snippets involve copy/pasting PHP into things like blocks or nodes. To accomplish this, you need to enable the PHP Filter module, included with Drupal core. Be very careful about who has access to use this filter; ideally, it should be User 1 and no one else. For more on filter system security, see .Snippets in the handbook are user-submitted; that is, anyone with a Drupal.org account can add a snippet. They are not reviewed or moderated—use them at your own risk! You should always read snippets over to make sure nothing looks out of the ordinary, test them out first, and give them your own security review following the security practices at http://drupal.org/writing-secure-code.There are snippets of code under several categories. The two sections most used are the Theme snippets (http://drupal.org/node/45471) and the PHP snippets (http://drupal.org/handbook/customization/php-snippets). Theme snippets use the methods outlined in this chapter to provide short pieces of code that can help customize the look and feel of your site. The PHP snippet section is further broken down—following is a quick list of the important sections:
- Mini modules
- These are very simple modules that may be copied and pasted to accomplish a particular task. There are instructions for using mini modules at http://drupal.org/node/70903.
- PHP block snippets
- These snippets create custom blocks using the PHP filter module; they allow you to create your own dynamic blocks and place them wherever you like in your site.
- PHP block visibility settings
- In contrast to the block “content” snippets listed previously, these snippets control when your blocks will appear to visitors. The basic block configuration allows you to use checkboxes for limiting visibility by role and mark specific pages on which you wish the block to appear. These snippets use a wider range of criteria to give you more control over visibility.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauWhat we’ve covered here is really just the tip of the iceberg in terms of things that can be done in your theme, but we’ve exposed you to all of the basic concepts. We’ve covered how to alter CSS for your theme; how to change the page structure and node content structure; and how to override template files, variables, and theme functions. Hopefully, these exercises gave you an idea of the power of Drupal’s theming system. There are many more ways in which themes can alter Drupal’s output and set up rules for how content and pages are structured based on the area of the site in which they appear—or really, on any criteria at all.More information on theming can be found at http://drupal.org/theme-guide, and books dedicated to Drupal theming are available if you want to continue down the path to becoming a theming ninja.Drupal’s theme layer attempts to be supremely flexible, allowing knowledgeable themers to alter all aspects of the page in any way they would like. Yet it is just a set of tools. Like web design itself, Drupal theming is limited only by the creativity and skills of those who are creating and implementing the theme. In the right hands, Drupal can make websites as beautiful and functional as anyone can imagine.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- References
- InhaltsvorschauHere are the themes and modules we referenced in this chapter:
- Bluemarine theme: core
- Devel module: http://drupal.org/project/devel
- Foundation theme: http://drupal.org/project/foundation
- Skyliner theme: http://drupal.org/project/skyliner
- Zen theme: http://drupal.org/project/zen
Here are Drupal.org resources we referenced in this chapter:- Default templates and suggestions: http://drupal.org/node/190815
- Drupal development resources: http://drupal.org/node/147789
- Drupal theme guide: http://drupal.org/theme-guide
- Drupal contributed themes: http://drupal.org/project/Themes
- Drupal contributed theme engines: http://drupal.org/project/Theme+Engines
- Overriding theme functions: http://drupal.org/node/11811
- PHP tag coding standard: http://drupal.org/node/545
- PHPTemplate variables: http://drupal.org/phptemplate
- Secure code: http://drupal.org/writing-secure-code
- PHP Snippets: http://drupal.org/handbook/customization/php-snippets
- Theme Snippets: http://drupal.org/node/45471
- Updating themes: http://drupal.org/update/theme
Here are external resources we referenced in this chapter:- jQuery: http://jquery.com
- Kate: http://kate-editor.org
- Notepad++: http://notepad-plus.sourceforge.net
- Smultron: http://smultron.sourceforge.net
- TextWrangler: http://www.barebones.com/products/textwrangler
- Web developer toolbar: https://addons.mozilla.org/en-US/firefox/addon/60
- W3Schools: http://w3schools.com
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Appendix : Installing and Upgrading Drupal
- InhaltsvorschauThe first step to using Drupal, of course, is to actually get the software and install it. Drupal comes with an installation script that will walk you through a few screens to gather information and then set up your database and create your site settings file for you. We’ll look at everything you need to make that process run smoothly; you’ll find that installing Drupal is quick and painless once some basic requirements are in place.Once you have Drupal up and running, it’s important to keep your site up-to-date. New releases of contributed modules and Drupal core come out periodically to address critical security fixes, and it’s important to stay on top of updates as they are released. We’ll take a look at Drupal 6’s built-in Update Status module, which will notify you of updates available for your site, and we’ll talk about the steps required to update both individual modules and the Drupal core itself from one version to another.You will notice that many people (and even Drupal core’s documentation ) use the terms “updating” and “upgrading” interchangeably. They both refer to replacing existing code with newer code.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Before You Begin Installation
- InhaltsvorschauPrior to installing Drupal, it’s important to make sure that you can actually do so, and understand a bit about how Drupal is structured. This section provides a checklist of Drupal’s requirements, and also highlights important things in the Drupal file structure that are worth knowing before diving into the installation process.It’s important to have a few things ready prior to installing Drupal. A full list of requirements is available at http://drupal.org/requirements. Use the following as a basic checklist prior to installing Drupal:
- Ensure access to a web host or local development environment with the following:
- A web server, such as Apache (http://httpd.apache.org), which handles serving up Drupal’s pages to the browser. Having access to Apache’s mod rewrite extension also allows you to use Drupal’s “Clean URLs” feature, which transforms URLs like http://www.example.com/index.php?q=contact to http://www.example.com/contact.
- PHP (http://php.net), the dynamic scripting language that powers Drupal. Drupal 6 requires at least PHP version 4.3.5, although PHP 5.2 or higher is recommended. The requirements page at Drupal.org has more information on required and recommended PHP extensions, most of which are enabled in PHP by default.
- A database server, such as MySQL (http://mysql.com), where Drupal will store all of the content, data, and settings that it needs in order to function.This book assumes that you are using Apache and MySQL. For additional help and support with other web and database servers, see http://drupal.org/getting-started/6/install.
- Write down the following information from your web host:
- Your (S)FTP or SSH username and password, so you can put Drupal’s files into place.
- Your database server’s details, including username, password, and database name, so that Drupal can connect to the database. Some web hosts also require additional information to access the database, such as specifying a remote hostname or a specific database port.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Installing Drupal
- InhaltsvorschauOnce you have met all of the requirements and gathered the information you need, you can get down to the installation. These instructions assume that you have already created your database, downloaded Drupal, and placed the extracted files on your web server:
- Set Drupal up to create your settings for you. Within Drupal, copy sites/default/default.settings.php to sites/default/settings.php—that is, without the default. at the beginning of the filename. You will also need to make sure that the new settings.php file is writable, such as with the command
chmod 666 or chmod a+w sites/default/settings.php. Your web host should have more information on how to make files writable in their environment. Also see the documentation in the Drupal handbook under http://drupal.org/node/202483.Make sure that you copy the file, not simply rename it. Drupal needs both files to exist in order to create your settings file for you properly.
- Now you can navigate to http://www.example.com/install.php to begin the installation process.
- The first page of the installation allows you to choose a language, as shown in . By default, the only language available is English. However, you may also download other translations and install Drupal in your language of choice. has more information on installing and configuring multilingual sites. Go ahead and click the Install Drupal in English link.The next screen will initially check for correct permissions before letting you proceed. You may need to change permissions on the parent sites directory, depending on your host configuration. View the help pages referenced in the installer error messages for more details.
Figure : Language selection for installing Drupal- Providing all went as expected, you should see a screen asking for your database credentials, as pictured in .
Figure : Database configuration during the Drupal installationEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Keeping Drupal Up-to-Date
- InhaltsvorschauIt’s not enough to just get Drupal installed, however; you also need to make sure to keep it up-to-date. New releases of modules and Drupal core come out periodically, most of which fix problems, some of which add new whiz-bang features, and some of which address critical security problems.When discussing updates, it helps to have some background information about Drupal’s version numbering system. For all the gory details, see http://drupal.org/handbook/version-info, summarized in .Each “major” release of Drupal core gets a new number: Drupal 5, Drupal 6, Drupal 7, and so on. A new major Drupal version is released every 12–18 months, and consists of new features, improved usability, and more flexible APIs. Throughout a major version of Drupal’s release cycle, several “minor” versions of Drupal are also released, such as 6.0, 6.1, and 6.2. Minor Drupal versions fix critical security problems and important bugs as well.Releases of projects like contributed modules, themes, and translations have a version naming scheme such as 6.x-1.3. The “6.x” indicates the major version of Drupal that it is intended to work with; in this case, Drupal 6. The “1” indicates the “major” release of the contributed module. And the “3” indicates that this is the third bug fix release of this major release of the module.Some releases also have “extra” version information, such as “-beta4” or “-rc2.” These indicate that the modules are still in development, but available for testing.
Figure : Drupal version numbers explainedUpdates between minor versions of Drupal core and modules, such as between Drupal 6.3 to 6.4, or Views module 6.x-2.0 to 6.x-2.1, are normally fairly painless, as long as your site is kept up-to-date. Updates between major versions, however, such as Drupal 6.3 to 7.0, or Organic Groups module 6.x-1.0 to 6.x-2.0, and especially to 7.x-1.0, will need special care, as the changes are generally quite extensive.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Updating Drupal Core
- InhaltsvorschauUpdating your site often sounds much scarier than the actual experience is. In addition to the included UPGRADE.txt file, the online handbook has a great deal of documentation available at http://drupal.org/upgrade/ and a helpful support forum at http://drupal.org/forum/21. The most important step to remember is creating and testing backups of your site.It cannot be stressed enough how important backups are when doing upgrades. This holds true for upgrading both Drupal core and contributed modules. You need to make sure you back up both essential parts of a Drupal site: the filesystem and the database. Every system can have a different way to do backups, so that will not be covered in detail in this appendix. You can ask your system administrator or refer to the backup section of the upgrade guide on Drupal.org at http://drupal.org/upgrade/backing-up-the-db. Make sure that you test the backups as well so that you are sure that you can recreate your site if something goes awry.Updating your out-of-date modules requires manually downloading the necessary files from Drupal.org and placing them on your server just as you did the first time you uploaded them. Drupal does not automatically download updates. This is to prevent overwriting existing module code before you have a chance to test it. For example, it’s possible that a module may make a change that requires a newer version of PHP than you have installed, which could result in fatal errors on your site if the files were downloaded blindly. Always test out updated modules on a test server before deploying them on your “live” site.This section walks you through the steps to update Drupal within a major version to the next minor release number—for example, if you are using Drupal 6.3 and need to upgrade to Drupal 6.4. When upgrading to a new major version of Drupal, such as Drupal 7, the steps are essentially the same, except that you must also upgrade all of your contributed and custom modules and themes at the same time.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Updating Contributed Modules
- InhaltsvorschauDrupal’s contributed projects tend to move more quickly than Drupal core and therefore require more updates within a Drupal version’s life cycle. You can upgrade multiple modules at the same time, although it’s best to do one at a time to reduce the chance of errors, and to allow you to isolate problems that might come up during an upgrade.To update contributed modules, follow these steps. You will see that the process is the same as the one used for Drupal core, only the files that are changed are a little different.
- Just as with Drupal core, you need to get the latest version of the module you wish to update. You should always read any release notes that are associated with the module to make sure that there are no special instructions for your update.
- It is still important to make backups of your entire Drupal installation, even though you are only updating a module. If something goes wrong you want to be able to restore the site to the state it was in before you began. So make your backups before proceeding.
- Log in to your site as User 1.
- Go to Administer→Site configuration→Site maintenance (admin/settings/site-maintenance) and select the Off-line radio button. Edit the “Site off-line message” to whatever you choose. Click “Save configuration” to take the site off-line.
- Now it’s time to replace the module files. Extract the module file that you downloaded from Drupal.org and completely replace the old module. To be thorough, you can delete the entire folder for the old module and then add the new, fresh module folder to the sites/all/modules directory.
- Go to http://example.com/update.php in your browser and click the Continue .
- Click the Update button to actually run the update script.
- Return to your site and make sure that everything looks okay. You should especially check the functionality that the particular module or modules provided for your site and make sure that there are no errors.
- Repeat steps 5 through 8 for each module that you wish to update.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - References
- InhaltsvorschauHere is a list of modules we referenced in this appendix:
- Update status: core
- Upgrade status: http://drupal.org/project/upgrade_status
Here is a list of the external references we used in this appendix:- Apache web server: http://httpd.apache.org
- MySQL: http://mysql.com
- PHP: http://php.net
- PostGreSQL: http://postgresql.org
- WampServer: http://www.wampserver.com
Here are the Drupal.org resources we referenced:- Drupal project: http://drupal.org/project/drupal
- Backward compatibility: http://drupal.org/node/65922
- Backing up the database and files: http://drupal.org/upgrade/backing-up-the-db
- Clean URLs: http://drupal.org/node/15365
- Installation guide: http://drupal.org/getting-started/6/install
- Multisite installation: http://drupal.org/node/43816
- Security: http://drupal.org/security
- Security RSS feed: http://drupal.org/security/rss.xml
- System requirements: http://drupal.org/requirements
- Upgrade guide: http://drupal.org/upgrade
- Upgrading Drupal forum: http://drupal.org/forum/21
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Appendix : Choosing the Right Modules
- InhaltsvorschauWith over 2,000 modules to choose from, and more added every single day, finding the contributed module you need for a given task can be a daunting process. Throughout this book, the authors have endeavored to highlight and identify most of the “must-have” modules, particularly architectural modules that are commonly used to build Drupal websites. We’ve also endeavored to cover modules that have a proven track record and are likely to continue to be used to build sites.However, each new website project has unique requirements that may be outside the scope of what this book has covered, and the landscape of the contributions repository is a constantly shifting space. Modules that were once critical building blocks may be abandoned or deprecated by superior alternatives, and new modules may come along that completely blow away anything else that came before them.This appendix, therefore, attempts to highlight some of the best practices used by those “in the know” for evaluating and selecting the right module for the job. It’s important to keep in mind that no simple set of guidelines—these included—can tell you everything about a module. The important thing to remember is that evaluating modules carefully before you commit to them will help prevent unpleasant surprises down the road.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Finding Modules
- InhaltsvorschauThe first step to choosing the right module for your needs is actually finding it. Fortunately, all Drupal modules (with only a few rare exceptions) are located directly on the main Drupal.org website, so there’s only one resource for finding them. Here’s how you do it.The module listing pages at http://drupal.org/project/Modules, pictured in , list modules by category (such as CCK or mail-related modules), by name alphabetically, and by the date they were last updated. Browsing these category-based pages can be useful for determining the modules that exist in a particular space, and keeping an eye on the modules that are frequently at the top of the date list helps highlight those with active maintainers.Drupal 5.x modules are not compatible with Drupal 6.x, and vice versa. To see an accurate list for your site, make sure to change the “Filter by Drupal Core compatibility” filter to show only those modules that are compatible with your Drupal version. You will have access to apply this filter only if you are logged in to the Drupal.org website. Getting an account is free and easy, and opens up many useful tools to you.
Figure : Module browse pages on Drupal.orgAnother nice Drupal.org “hack” is keeping an RSS reader pointed at http://drupal.org/taxonomy/term/14, which is a list of all the newest modules on Drupal.org as they are created.Drupal.org also provides a block for searching the downloads on the site, also pictured in . For example, searching for “wiki” brings up a list of modules with that keyword in their name or description. This allows you to drill down to modules specific to your needs faster than browsing by the default category view.The Drupal.org support forums at http://drupal.org/forum, particularly the “Before you start” forum at http://drupal.org/forum/20, can provide a wealth of information in the form of questions from other users about the modules they used for their own projects. Often, you can receive some helpful advice not only about the feature you’re trying to implement now, but also for future things your website will need to take into consideration. The “Drupal showcase” forum atEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Assessing a Module’s Health
- InhaltsvorschauAn open source project’s strength comes from the power of its base of contributors, and the Drupal project is no different. Although every line of code added or changed in Drupal core goes through rigorous peer review, contributed modules are more of a “Wild West” where anyone who jumps through a few basic hoops can add modules for everyone to download. The Drupal community strives to keep the barriers to contributing code back as low as possible in order to facilitate growing Drupal’s thriving development community. This approach has both pros (for almost any problem, there’s a module that either can get you fully or at least partway there) and cons (developers’ experience levels are varied, so contributed code can have inefficiencies and security problems, and developers can become overextended and unable to keep up with maintenance of their modules).Whether or not a module is well-maintained, its overall code quality, and how well-used it is in the overall community are all important factors to consider when selecting modules. This section will talk about determining these factors by closely inspecting the tools Drupal.org provides, starting with the central feature of all Drupal modules: the project page.Modules, themes, translations, and even Drupal core itself are all referred to as projects on Drupal.org. Each project has its own page at http://drupal.org/project/file_name, which contains a wealth of information that can be used to evaluate a module’s health.shows the first part of a module’s project page. Here you can find the name of the module’s maintainer (usually the original author and/or the module’s primary developer), the date the project was first created, a description of what the module does, and sometimes a screenshot showing what the module does.
Figure : The project page for the Devel moduleThe original project creation date can be useful when looking for time-tested solutions (if the module was created in the past week, it’s probably best to let it mature a bit before depending on it). But also be aware that some older modules may be legacy solutions that more modern modules deprecate.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - The People Behind the Code
- InhaltsvorschauEach contributor to Drupal is a unique individual who has his own areas of interest, expertise, background, and motivations for contributing. Some contributors are master programmers who live, breathe, sleep, and eat code. Some are backed by Drupal development and consulting companies, and are paid to maintain their modules. Others are hobbyists who run a fan club site and maintain one or two particular modules that act as the main backbone of their community. Still others help out for the fun of it, because it feels good and they enjoy it. There are those who get code as far as they need it, toss it out there, and move on to bigger and greener pastures. And, of course, there are those who are some, all, or none of the above.Therefore, a critical piece to evaluating a module is to also learn more about the humans behind the code. Drupal.org has a few useful tools to help.The first is the “Developers” link at the bottom of project pages (for example, http://drupal.org/project/developers/3060), which takes you to a table, shown in , displaying a list of the individual developers who are maintaining (or have maintained) the project. The data shown here are the commits, or code changes to a project, by everyone who has ever had access.From this information, you can get a general idea of who within the project has been working on it the longest, how active each contributor is, and how much experience each has with a given project’s code. A sign of a good, healthy project is lots of recent commit activity, along with numerous contributors in the list if some of the original folks are no longer around. If this list is small, and the last commit was several months ago, particularly if the project’s issue queue shows warning signs, it may be worth looking for alternative solutions, or perhaps offering the maintainer payment for the changes you need, in order to help entice her interest again.
Figure : A list of developers for the Drupal project, along with commit activityEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Getting Involved
- InhaltsvorschauBy far, the best way to keep up-to-date on what modules are the most useful, and to ensure that those modules do what you need, is to actually get directly involved and help. The Drupal community offers a myriad of ways for everyone, from the person who just installed Drupal for the first time yesterday to the person who has been coding since she was in diapers, to give something back.The “Getting Involved” handbook at http://drupal.org/getting-involved is the main “jumping-off” point for ways to get involved in the Drupal project. Here are a few that are suited to nonprogrammers as well:
- Issue queue cleanup
- While you’re evaluating modules, you’ll naturally be in the issue queue anyway. Why not take a few extra minutes and look for places you might be able to clean things up? If there are two or more similar issues, mark the higher-numbered one as a “duplicate.” See if a bug report is still valid, and if it’s not, mark it “fixed.” If you see a support request that you know the answer to, answer it. Every minute spent by someone other than the module maintainer on this type of activity is more time that she can spend improving her modules, and so this type of contribution is hugely appreciated by maintainers.
- Helping with user support
- If you’ve gotten as far as getting Drupal installed, congratulations! You now know enough to help someone else. Head to the Drupal forums or #drupal-support on irc.freenode.net and look for opportunities to answer other users’ questions. You’re guaranteed to learn a ton in the process.
- Filing issues
- If you come across a problem with a module, or something that you think would be really cool, file it as a detailed bug report or feature request in the module’s issue queue using the guidelines at http://drupal.org/node/317. Remember to click on the “Advanced search” link at the top of the issue queue first to check for an existing issue before creating one of your own.
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Summary
- InhaltsvorschauThe tips and techniques outlined in this chapter can help identify “must-have” modules long after this book is out of date. By assessing things such as how active a project’s maintainer is, how large the user community is around a project, and how well- and easy-to-read its code is, you can help make smart, future-proof choices on your module selection. And by getting involved directly in the community itself, you can meet the awesome people who make Drupal what it is, and become one of them yourself!Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- References
- InhaltsvorschauHere is a list of the resources referred to in this appendix:Bug report and feature request guidelines: http://drupal.org/node/317Case studies: http://drupal.org/casesContribute page: http://drupal.org/contributeContributed module list: http://drupal.org/project/ModulesCVS repository online: http://cvs.drupal.org/viewvc.py/drupal/contributions/modulesDevelopers list for the Drupal project: http://drupal.org/project/developers/3060Documentation team: http://drupal.org/contribute/documentation/joinDonate money: http://association.drupal.org/donateDrupal core project issue queue: http://drupal.org/project/issues/drupalDrupal.org forums: http://drupal.org/forumDrupal “Before You Start” forum: http://drupal.org/forum/20Drupal showcase forum: http://drupal.org/forum/25New York Observer case study: http://drupal.org/node/141187Planet Drupal: http://drupal.org/planetPopular Science magazine case study: http://drupal.org/node/233090Sony BMG MyPlay case study: http://drupal.org/node/241344Third-party resources: http://drupal.org/node/289913Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Appendix : Modules and Themes Used in This Book
- InhaltsvorschauEnde der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- InhaltsvorschauNot applicable.Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
- Inhaltsvorschau
- Modules:
- Administration menu 6.x-1.0 (http://drupal.org/project/admin_menu)
- FCKeditor module 6.x-1.3-rc1 (http://drupal.org/project/fckeditor)
- FCkeditor package 2.6.3 (http://fckeditor.net)
- IMCE 6.x-1.1 (http://drupal.org/project/imce)
- Theme:
- Garland (core)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Advanced help 6.x-1.0 (http://drupal.org/project/advanced_help)
- Content Construction Kit (CCK) 6.x-2.0-rc10 (http://drupal.org/project/cck)
- Filefield 6.x-3.0-alpha5 (http://drupal.org/project/filefield)
- Views 6.x-2.0-rc4 (http://drupal.org/project/views)
- Theme:
- Wabi 6.x-1.1 (http://drupal.org/project/wabi)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Advanced help 6.x-1.0 (http://drupal.org/project/advanced_help)
- Amazon 6.x-1.0-beta3 (http://drupal.org/project/amazon)
- Content Construction Kit (CCK) 6.x-2.0-rc10 (http://drupal.org/project/cck)
- CSS Injector 6.x-1.3 (http://drupal.org/project/css_injector)
- Fivestar 6.x-1.13 (http://drupal.org/project/fivestar)
- Search (core)
- Views 6.x-2.0-rc4 (http://drupal.org/project/views)
- Voting API 6.x-2.0-beta6 (http://drupal.org/project/votingapi)
- Theme:
- Nitobe 6.x-1.6 (http://drupal.org/project/nitobe)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Advanced help 6.x-1.0 (http://drupal.org/project/advanced_help)
- Diff 6.x-2.0 (http://drupal.org/project/diff)
- Freelinking 6.x-1.6 (http://drupal.org/project/freelinking)
- Markdown filter 6.x-1.0 (http://drupal.org/project/markdown)
- Pathauto 6.x-1.1 (http://drupal.org/project/pathauto)
- Token 6.x-1.10 (http://drupal.org/project/token)
- Views 6.x-2.0-rc4 (http://drupal.org/project/views)
- Theme:
- Barlow 6.x-1.0 (http://drupal.org/project/barlow)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Advanced help 6.x-1.0 (http://drupal.org/project/advanced_help)
- Trigger (core)
- Views 6.x-2.0-rc4 (http://drupal.org/project/views)
- Views Bulk Operations 6.x-1.1 (http://drupal.org/project/views_bulk_operations)
- Workspace 6.x-1.3 (http://drupal.org/project/workspace)
- Workflow 6.x-1.0-rc1 (http://drupal.org/project/workflow)
- Theme:
- Light Fantastic 6.x-1.0 (http://drupal.org/project/lightfantastic)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Advanced help 6.x-1.0 (http://drupal.org/project/advanced_help)
- Content Construction Kit (CCK) 6.x-2.0-rc10 (http://drupal.org/project/cck)
- Custom Pagers 6.x-1.10-beta1 (http://drupal.org/project/custom_pagers)
- FileField 6.x-3.0-alpha5 (http://drupal.org/project/filefield)
- ImageCache 6.x-1.0-alpha2 (http://drupal.org/project/imagecache)
- ImageField 6.x-3.0-alpha1 (http://drupal.org/project/imagefield)
- Token 6.x-1.10 (http://drupal.org/project/token)
- Views 6.x-2.0-rc4 (http://drupal.org/project/views)
- Theme:
- Ubiquity 6.x-1.x-dev (2008-May-31) (http://drupal.org/project/ubiquity)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Book (core)
- Content Translation (core)
- Forum (core)
- Internationalization 6.x-1.0-beta1 (http://drupal.org/project/i18n)
- Localization (core)
- Localization client 6.x-1.3 (http://drupal.org/project/l10n_client)
- Theme:
- Dreamy 6.x-1.3 (http://drupal.org/project/dreamy)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Advanced help 6.x-1.0 (http://drupal.org/project/advanced_help)
- Content Construction Kit (CCK) 6.x-2.0-rc10 (http://drupal.org/project/cck)
- Calendar 6.x-2.0-rc3 (http://drupal.org/project/calendar)
- Date 6.x-2.0-rc3 (http://drupal.org/project/date)
- Flag 6.x-1.0-beta5 (http://drupal.org/project/flag)
- Views 6.x-2.0-rc4 (http://drupal.org/project/views)
- Theme:
- Deco 6.x-1.1 (http://drupal.org/project/deco)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Content Construction Kit (CCK) 6.x-2.0-rc10 (http://drupal.org/project/cck)
- FileField 6.x-3.0-alpha5 (http://drupal.org/project/filefield)
- ImageCache 6.x-1.0-alpha2 (http://drupal.org/project/imagecache)
- ImageField 6.x-3.0-alpha1 (http://drupal.org/project/imagefield)
- Token 6.x-1.10 (http://drupal.org/project/token)
- Ubercart 6.x-2.x-dev (2008-Nov-3) (http://drupal.org/project/ubercart)
- Theme:
- Pixture 6.x-1.1 (http://drupal.org/project/pixture)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar. - Inhaltsvorschau
- Modules:
- Devel 6.x-1.9 (http://drupal.org/project/devel)
- Theme:
- Bluemarine (core)
Ende der Inhaltsvorschau. Der weiterere Inhalt dieses Abschnitts ist hier nicht einsehbar.
Zurück zu Using Drupal
