Chapter 2. Drupal Jumpstart

This chapter, intended for readers who are new to Drupal, provides a tour of its capabilities, as well as definitions for its sometimes obscure terminology. We’ll demonstrate how Drupal can be used “out of the box” 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 Appendix A, 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

Comment (core)

Allows users to create replies to node content

User (core)

Allows users to log in, and provides 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 http://www.example.com/node/1

Module Filter (http://drupal.org/project/module_filter)

Allows administrators to quickly filter the list of modules by keyword

Contact (core)

A simple form that site visitors may use to send inquiries to website owners

The completed website will look as pictured in Figure 2-1 and at http://jumpstart.usingdrupal.com.

The completed Mom and Pop, Inc., website

Figure 2-1. The completed Mom and Pop, Inc., website

Case Study

Mom and Pop, Inc. is a small organic grocery store in the midwestern United States run by its co-owners, Jeanne and Mike. Its 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 with code, 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 Goldie to get around to doing it. As a result, the site is frequently out of date and not doing much other than costing Mike and Jeanne 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, and a contact form to receive inquiries from customers.

Mike and Jeanne also would like a place to post announcements, where they can showcase weekly deals, in-store events, or general goings-on in the community. Visitors to the site should be able to comment on these announcements, with anonymous visitors’ comments going into an approval queue first.

Neither Mike nor Jeanne is very technical, so it’s important that they have a simple administration panel. 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.

Implementation Notes

The Implementation Notes section of each chapter will discuss, compare, and contrast various options for fulfilling the client’s needs in Drupal, and explain how we decided on the specific solutions chosen for each chapter.

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 “Drupal core” or just “Drupal.” 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 as http://www.example.com/about.

Drupal also provides a robust roles and permissions system, which we can use to separate Goldie’s tasks (website maintenance) from Mike and Jeanne’s tasks (managing the daily website content) and from the customers on the site (who can do only things such as leave comments). There are also administrative tools, such as the Dashboard and Shortcut modules, that can help Goldie provide a specifically tailored administrative interface for Mike and Jeanne.

Drupal also comes with a module called Contact, which can be used to build a simple contact form for any website. Different categories may be set up, and each one can optionally send mail to a different email address. This feature is useful for sites with different support personnel in different departments, for example.

And finally, the announcements section, as we will see, can be handled using just the default Article content type that ships with Drupal.

Spotlight: Drupal’s Administration Interface

Unlike some other content management systems, which have a totally separate back-end administration tool from the front-facing website, in Drupal the website itself and the administration tools to manage it are integrated together. In building out your site, you will frequently pop in and out of the administration section by clicking “edit” on a piece of content, or “configure” on a particular part of the page.

Figures 2-2 and 2-3 illustrate what Drupal looks like out of the box, as well as the various ways to enter the administration section and pointers on how the administrative interface works.

Different methods of navigating to the administration section

Figure 2-2. Different methods of navigating to the administration section

Note

If you’re inheriting a Drupal site created by someone else, your administration screens may not look identical, or even very close. Everything in Drupal is very modular, flexible, and customizable, and that includes its administration tools. The screenshots here demonstrate what Drupal 7 provides out of the box through a combination of Dashboard, Toolbar, Shortcut, Overlay, and Contextual Links modules, as well as the Seven administration theme. We’ll talk a lot more about modules and themes later in the chapter.

A diagram of Drupal’s administration section

Figure 2-3. A diagram of Drupal’s administration section

The administrative interface of Drupal is split into the following sections, visible in the toolbar along the top of the screen:

Dashboard

While initially quite sparse, the Dashboard allows you to set up a custom administrative landing page for your content editors, a “one-stop shop” for all of the things they need to know, such as the recent users who’ve registered to the site, or comments that are awaiting approval.

Content

Creating, editing, and deleting content and comments can be done from the Content administration link. You can also manage workflow information, such as whether or not the content is published, or whether comments awaiting moderation are approved.

Structure

Configuration related to how your site is fundamentally built—for example, choosing what data you wish to capture in your content, and how you navigate to that content—is housed in the Structure section.

Appearance

This menu allows you to choose and configure themes, which control the look and feel of your site. We’ll be discussing the Appearance section later in Spotlight: Themes.

People

This is where you manage the people who administer and visit your site, as well as what they’re allowed to do. This section will be discussed in more depth in Spotlight: Access Control.

Modules

Modules are a central construct in Drupal. Installing and enabling modules is how you add new features and change the existing behaviour of Drupal to meet your precise needs. This concept will be covered in much more detail in Spotlight: Modules.

Configuration

The Configuration section is where most modules will put their administration links. Configuration links are categorized under headings such as “User interface” and “Web services.”

Reports

The Reports section is useful for both keeping up with maintenance as well as gaining insight into how your audience interacts with your site.

  • The Status report offers a quick glimpse of your site’s overall health and will warn you of configuration problems.

  • The Recent log entries report allows you to monitor site activity as it happens; errors, user activity, content notifications, and more will appear here.

  • The Available updates report will show whether your modules and themes are out of date, and also allows you to install updates from within the user interface.

  • A variety of “Top” reports (e.g., Top ‘access denied’ errors, Top search phrases) will show you where your users are running into the most errors, what your users are searching for the most, and—if you’re running the core Statistics module—the most popular content on your site.

Help

The Help section contains some basic instructions to help you get started, as well as a help page for each module you have installed. These pages provide a general overview of what the module does, as well as some specific uses and how to perform them. This is a great section to visit the first time you install something new to get a feel for how it works.

Note

Once you know your way around Drupal a bit, the “Administration menu” module can speed up your navigation through the administrative panel; it turns the top-level links into drop-downs that contain all of the subitems, so you can get to many places in just a single click.

Hands-On: Changing Administrative Settings

You’ll spend a lot of time in Drupal’s administration panel while building out your sites, so let’s walk through a simple example of configuring your site: changing Drupal’s “site name” in the upper-left corner to reflect the customer for whom the site is being built.

  1. In the administrative toolbar, click Configuration. The Overlay will appear, indicating that you’re currently in an administrative context.

  2. Under System, choose the “Site information” link (admin/config/system/site-information). This page contains some overall settings for your site, many of which were established during installation.

  3. Change the “Site name” value from whatever it currently is to “Mom and Pop, Inc.”

  4. Click “Save configuration” to save your settings, then click the X in the upper-right corner to close the Overlay and return to your site’s frontend.

  5. The site name in the upper-left corner should now read “Mom and Pop, Inc.,” as pictured in Figure 2-4.

    Newly customized site name

    Figure 2-4. Newly customized site name

    Note

    Another useful setting on this page is “Default front page,” which allows you to customize which path Drupal will load when you click the Home link or site logo.

Spotlight: Content Management

Drupal’s primary function is to enable users such as Mike and Jeanne to manage their own content. This section offers a tour of some of the most basic tools for content management in Drupal.

Content

As discussed in Chapter 1, 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: “Basic page,” intended for static content such as an About Us page, and “Article,” intended for time-sensitive content such as press releases. But, like most things in Drupal, content types are fully configurable. Figure 2-5 shows the “Create content” page on a typical Drupal site with several content types available. This page is found under “Add content” (node/add) in either the Navigation block or the default Shortcut menu.

A list of available content types

Figure 2-5. A list of available content types

Figure 2-6 shows an example of a typical node form, which is used to add or edit a piece of content. Each node has a Title field, which identifies the node in content listings and controls the title of the web page when viewed, and most nodes also have a Body field, which holds its primary content. Additional fields of varying types—for example, text, numeric, or file upload fields—may also be added to a basic node form for more granular data entry. The next chapter covers extending the fields on the node form in depth.

At the bottom of the node form fields is a set of more advanced options, enclosed in a set of vertical tabs. These tabs display the current value of each setting, and you can click them to make adjustments. 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 most other settings, so the tabs simply do not show up on the form for these users.

A typical node form in Drupal

Figure 2-6. A typical node form in Drupal

Note

People 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 often 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 “Basic page” node affects only the content of a given web page: its title, its body, and any additional properties such as a byline or rating.

The Body field on a node can optionally provide a summary, which is a short blurb that entices people to read further. Summaries are displayed in most content listings, in RSS feeds, and in other places. When a summary is provided, the text in the Body field is displayed only when a user is looking at a piece of content directly.

Warning

The “Text format” of the Body field, and other rich-text fields, is an important setting. Text formats limit the characters that can be entered into a given field, and configuring them incorrectly can have a significant impact on the security of your site. We’ll use the default (secure) settings for this chapter in the interest of brevity, but Chapter 4 has all the gory details on more permissive text format configuration.

Nodes can have a variety of options applied to them, including the ability to track and revert revisions, the ability to turn on commenting on the content type, and the ability to default to Unpublished so new nodes are not immediately visible on the site. You may set these options on a per-node basis, or specify the defaults for all nodes of this type in the administration section for content types at Structure“Content types” (admin/structure/types) in the administrative toolbar and pictured in Figure 2-7.

The content type administration form

Figure 2-7. The content type administration form

Warning

When default options for content types are switched, these settings are not retroactively applied to content that’s already been created. It pays to spend some time thinking about what settings you’d like on each content type before you begin creating lots of content on your site.

Nodes that have the “Promoted to front page” publishing option checked appear on the default front page listing, available via the path http://www.example.com/node, as pictured in Figure 2-8. Nodes are displayed one after another, with “Sticky at top of lists” nodes on top, and the rest of the list ordered chronologically starting with the most recent.

The default front page view

Figure 2-8. The default front page view

Note

Front page” is a bit of a misnomer; the listing at /node is the front page only by default; you can change the home page to whatever page you’d like under the ConfigurationSystem“Site information” page (admin/config/system/site-information), covered in the previous hands-on section.

Although this default view of content is very basic, you can create almost any type of content listing imaginable with the Views module, discussed in depth in Chapter 3 and used extensively throughout the rest of the book.

You can make changes to content workflow once it’s created on the node itself, by editing it directly, or in bulk by going to the administrative toolbar and clicking the Content (admin/content) link, pictured in Figure 2-9. Here, content may be deleted, published, or unpublished, or have various workflow options set.

The Content administration page

Figure 2-9. The Content administration page

Note

If you ever “lose” a piece of content (for example, you create a node that is not promoted to the front page, and forget to add a Navigation menu item pointing to it), you can always find it again from the Content administration page. This page is sometimes colloquially referred to as the “node lost and found,” and can be very helpful, since losing a piece of “missing” content is pretty easy to do when you’re first starting out.

Comments

The core Comment module allows website visitors to post replies to the content within a node, enabling them to discuss the topic at hand directly with the author as well as with one another. Figure 2-10 shows commenting in action.

The Comment module allows visitors to discuss a piece of content

Figure 2-10. The Comment module allows visitors to discuss a piece of content

Most content types have comments enabled by default, although the “Basic page” type has commenting turned off initially (as it doesn’t make much sense for visitors to discuss your About Us page). You may configure additional comment settings per content type from the administrative toolbar at Structure“Content types” (admin/structure/types). These settings include specifying whether to require previewing of comments before posting them, as well as the number of comments to display on the page. We’ll cover a few of these settings later in the chapter.

Comments may also optionally be placed in a moderation queue rather than being immediately visible on the site, which can be useful as a basic spam deterrent. Comment administration facilities are available as a subtab on the main Content screen at ContentComments, as shown in Figure 2-11.

The Comment moderation queue administration page

Figure 2-11. The Comment moderation queue administration page

Note

There are a number of modules that help ease the burden of dealing with spam and abusive content. We’ll discuss some of the options later in this chapter in Spotlight: Content Moderation Tools.

Navigation

Hand-in-hand with creating content is the ability to navigate to it on the site. Drupal provides a built-in module called Menu for this purpose. Menus hold the navigation links to various web pages on a Drupal site. Drupal comes with four default menus, and you can also add your own:

Main menu

A menu provided for custom navigation needs, typically displayed very prominently in the site’s design. Major sections of the site such as Home and About Us tend to be placed in the Main menu.

User menu

Displays links relevant to the current user, such as “My account” and “Log out.” This menu is generally placed in the upper-right corner. In the default configuration, these links will be printed twice: once for administrators in the Toolbar, and once for end users.

Navigation

A general menu that acts as the default “dumping ground” of links offered by new modules, when they are not strictly administrative tasks. For example, when you enable the Forum module, a “Forums” link to the forum listing page is added to the Navigation menu. Many modules offer links under the Navigation menu that are originally disabled, but can be optionally turned on.

Management

Holds links to administration tasks, essentially duplicating the administrative toolbar at the top of the page, for sites that don’t use the default Toolbar module.

Note

As with the “Basic page” and “Article” content types, you don’t have to use these prebuilt menus. They are merely a potential starting point that can help you get your site up and running quickly. And like everything else in Drupal, you can also make your own!

Figure 2-12 shows an example of all four menus in the default core Bartik theme. Themes will be discussed in more detail later in the section Spotlight: Themes.

Drupal’s built-in menus: Management, User, Main, and Navigation

Figure 2-12. Drupal’s built-in menus: Management, User, Main, and Navigation

Note

You can configure which menu to use for “Main links” and “Secondary links” at StructureMenusSettings tab (admin/structure/menu/settings).

Under normal conditions, these two menus are different (they default to “Main menu” and “User menu,” respectively). However, if you set both the Main and Secondary menus to the same value, this creates a sort of drill-down effect in which the top-level items are displayed in the “Main menu” region, and any subitems of the currently active “Main menu” link are displayed dynamically in the secondary region.

The powerful Menu Block module generalizes this one-off feature, allows the creation of additional “sub” menus, and provides a variety of other advanced configuration options.

Blocks

Blocks are smaller chunks of content that you can place in your pages. Examples of some default blocks provided are “Who’s online,” which shows a listing of users currently logged in; “User login,” which displays a login form to anonymous users; and “Recent comments,” which shows a list of the newest comments on the site. The Navigation bar in the sidebar, the “Powered by Drupal” text at the bottom, and even the entire content area of the page are blocks! You can also make your own custom blocks: for example, you might create a block to display an announcement about an upcoming event.

Figure 2-13 shows the Block administration page under StructureBlocks (admin/structure/block). Blocks are placed within a region of a page. Examples of regions are “Sidebar first,” “Footer,” and “Content.” Region names, and exactly where they appear on a page, vary depending on the theme (or design) of your site; some themes may define additional regions such as “Banner ad” and remove or change some of the default regions. Therefore, blocks must be configured on a per-theme basis. We’ll discuss more about themes and regions later in Spotlight: Themes. You may use the arrow handles on the side to drag blocks to different regions. To see a visual representation of what the regions look like, as pictured in Figure 2-14, click the “Demonstrate block regions” link.

The Block administration page for the Seven administration theme

Figure 2-13. The Block administration page for the Seven administration theme

Note

One frequently asked question is how blocks and nodes differ, as both display content. One general rule of thumb is that blocks are typically supplementary information to the actual content on the page. Block content also usually either changes often (in the case of the “Who’s online” block), or consists of temporary information such as a blurb that’s displayed on the front page for a few days. Block content is also not searchable, so if the content needs to be referenced permanently, a node is a much better choice.

Block regions for the Bartik theme indicate visually where blocks will be displayed

Figure 2-14. Block regions for the Bartik theme indicate visually where blocks will be displayed

You can customize the visibility of blocks, as well—for example, to show blocks on only certain pages or only to users with certain roles. If the core PHP filter module is enabled, you may also optionally use PHP to specify complex visibility settings—for example, to display a Help block to any users who have been members for less than a week. There is also an option to let users control the visibility of certain blocks themselves, so they have more control over their browsing experience.

Warning

Be careful with using and giving access to use PHP on a Drupal site. Although PHP is an extremely powerful tool, the ability to work with it within a web application like Drupal opens the door for security problems and site crashes. We’ll harp on this point again in Hands-On: Configuring Permissions, when we talk about access permissions.

Hands-On: Content Management

Out of the box, our wonderful Drupal site (pictured in Figure 2-15) 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 pieces of content—the About Us page and a welcome announcement—and begin to build our website’s navigation. We’ll also add a few blocks for extra pizzazz.

Drupal, after a fresh installation

Figure 2-15. Drupal, after a fresh installation

Creating a Basic Page

First, we’ll make a simple About Us page to get the hang of Drupal’s content creation and editing tools.

  1. Go to “Add content”“Basic page” (node/add/page) in either the Navigation block or the Shortcut bar.

  2. Enter the page’s Title, Body, and other settings provided in Table 2-1 and pictured in Figure 2-16. Because this is a static page, we’ll also place it into our site’s main Navigation menu. Finally, we’ll give the page a friendly path of http://example.com/about instead of http://example.com/node/1 by providing a “URL path alias.”

    Table 2-1. About Us page values

    Setting

    Value

    Title

    About Us

    Body

    Our store has been providing organic food to the community since 1978. Come and see us at:

    123 Main Street

    Home Town, MN

    Store hours: 12pm–12am

    Text format[a]Filtered HTML (default)

    Menu settings

    • Provide a menu link

    Checked

    • Menu link title

    About Us (default)

    • Description

    Learn more about Mom and Pop, Inc.

    • Parent item

    <Main menu> (default)

    • Weight

    0 (default)

    URL path settings
    URL aliasabout

    [a] We’re breezing right by that “Text format” field at the moment, but this is actually an important Drupal security concept to understand, and will be covered in more detail in Spotlight: Text Formats and Filters. Don’t miss it!

    Creating the site’s About Us page

    Figure 2-16. Creating the site’s About Us page

    Note

    Setting URL aliases by hand can be tedious. The Pathauto module, covered in Chapter 7, allows you to set up customized rules that automatically generate friendly URLs for all of your website content (http://example.com/content/about), users (http://example.com/user/admin), and more.

  3. When you’ve completed these steps, you should see the new page appear, and there should now be two tabs in the site’s main navigation: About Us and Home, as shown in Figure 2-17.

    The completed About Us page

    Figure 2-17. The completed About Us page

    Note

    If you forgot to enter a menu item and navigate away from a page, it can be tricky to find it again without manually going to a path like http://www.example.com/node/1. The Content administration page under Content (admin/content) in the administrative toolbar can help you track down straggler pages.

Congratulations! You’ve just created your first of many nodes in Drupal!

Creating an Article

Next, let’s experiment with creating an Article—Drupal’s other default content type. Unlike “Basic page,” which contains just a Title and Body field, Articles can also provide Tags (or keywords) and an Image on each post. Articles also have comments enabled, and automatically get posted to Drupal’s default home page in reverse-chronological order, making them useful for things like announcements. So, let’s announce the creation of our new website!

Note

The features described here for “Basic page” and Article are only their default behavior. It’s possible to fully customize the capabilities of these or any other content types under the Structure“Content types” (admin/structure/types) administrative page. Chapter 3 will go into much more detail about doing this sort of customization; for now, we’ll stick with the defaults.

  1. Go to “Add content”Article (node/add/article) in either the Navigation block or the Shortcut bar.

  2. Enter the article’s Title, Body, and other settings provided in Table 2-2 and pictured in Figure 2-18, and click Save. This time, we’re not going to supply a menu item, because this announcement will appear on our home page so we’ll have a way to navigate to it. We’ll also enter a Summary for this post, so that the home page shows a small bit of text but requires a user to click “Read more” to read the article’s entire contents.

    Table 2-2. Welcome announcement values

    Setting

    Value

    Title

    Welcome to our new website!

    Tags

    announcements, website
    Summary (click “Edit summary” link next to the Body field to expose)Read all about our new website and what it means for you!
    Body

    Welcome to our new website, powered by Drupal! Don’t know what Drupal is? Don’t worry; we don’t either. :)

    The important thing is that we can now update our website much faster and more often than before! We’ll be posting about in-store promotions, great upcoming deals, and general community events.

    Stay tuned for further announcements!

    Text formatFiltered HTML (default)
    Image(upload firebird.png in the /assets/ch02-jumpstart folder, or any other image you have lying around)
    Alternate text (visible after uploading image)Pa’s prized 1978 Pontiac Firebird
    Creating the site’s first article

    Figure 2-18. Creating the site’s first article

  3. You should now be redirected to the article page, displaying your full-size image, body text, and tags, as well as a comment form. By clicking the Home link, you’ll be taken to the site’s home page, which will display a slightly smaller version of the image, as well as the Summary text, as shown in Figure 2-19.

    Note

    The Tags field is a built-in example of Drupal’s robust categorization system, called Taxonomy. While we won’t get too in depth into Taxonomy for this chapter; you can read much more about it in detail in Spotlight: Taxonomy.

    Article shown in summary view on home page

    Figure 2-19. Article shown in summary view on home page

Managing Site Navigation

Great! We now have some simple content on the site, and our Navigation menu is starting to come together. However, there’s something a little funny going on: our tabs in the top-left corner are displayed in alphabetical order, which puts About Us before Home. It would make a lot more sense for Home to come first, so let’s fix that by reordering the items listed in the menu:

  1. Go to StructureMenus (admin/structure/menu) in the toolbar, and click “list links” next to “Main menu” (admin/structure/menu/manage/main-menu).

  2. Using the handles on the left side, drag the Home item above the About Us item, as shown in Figure 2-20. You’ll see a note that the changes will not be saved until the form is submitted.

  3. The yellow background and asterisk indicate that the changes are not yet saved. Make sure to click “Save configuration” to save your menu settings.

The menu administration screen allows you to reorder menu links

Figure 2-20. The menu administration screen allows you to reorder menu links

Now, if we close out of the Overlay and return back to our site’s frontend, our menu should have Home listed first. That’s more like it!

Configuring Blocks

Next, let’s start to play around a bit with blocks on the site. Mike and Jeanne don’t know what Drupal is, which is going to result in all sorts of awkward questions about that “Powered by Drupal” block in the footer. So let’s remove it. Additionally, they want to be able to show off the latest weekly deal prominently on the home page, which is the perfect use for a custom block.

  1. Begin by navigating to the Block administration page at StructureBlocks (admin/structure/block). Here, you will see a list of all of the available regions.

  2. Let’s start by removing the “Powered by Drupal” block. Scroll down the page to the Footer region, click the handle next to the “Powered by Drupal” block, and move it down to the Disabled region, as pictured in Figure 2-21.

    Use the drag-and-drop handles to remove the “Powered by Drupal” block

    Figure 2-21. Use the drag-and-drop handles to remove the “Powered by Drupal” block

    Note

    In addition to being able to drag and drop the blocks into the region of your choice, you can also use the drop-down list in the Region column to choose the region.

  3. As with menus, the yellow background and asterisk indicate that the changes are not yet saved. Click the “Save blocks” button to remove the block from the footer.

  4. Next, let’s look into that weekly deals block. We’ll start by finding a suitable place for this announcement. Click the “Demonstrate block regions” link (admin/structure/block/demo/bartik) at the top of the page to see a preview of available block regions and their styling. Notice the Featured region displayed along the top, with a gray background. That should help it stand out from the rest of the page. Click “Exit block region demonstration” in the upper left to return to the Block administration page.

  5. Next, we need to add our own custom block. Click the “Add block” link at the top of the page (admin/structure/block/add).

  6. Enter the settings from Table 2-3 as shown in Figure 2-22. Use the “Page-specific visibility settings” to ensure that the block shows up only on the home page. We can also add the block to the Featured region right from this form.

    Block configuration form

    Figure 2-22. Block configuration form

    Table 2-3. Settings for weekly deals block

    Field

    Value

    Block-specific settings

    Block titleThis week’s deals!

    Block description

    Weekly deals

    Block body

    New this week: Oranges! Only 42 cents each. Yum!

    Text formatFiltered HTML (default)

    Region settings

    Bartik (default theme)Featured

    Seven (administration theme)

    None (default)

    Visibility settings: Pages

    Show block on specific pages

    Only the listed pages

    Pages

    <front>

  7. After saving this form with the “Save block” button, you’ll return to the main Block administration page. Return to your site’s home page, which should now look as pictured in Figure 2-23.

“Weekly deals” block added; “Powered by Drupal” block removed

Figure 2-23. “Weekly deals” block added; “Powered by Drupal” block removed

Spotlight: Modules

As discussed in Chapter 1, 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 Drupal community and available for download from Drupal.org. This section discusses everything you need to know about modules.

Module Administration Page

The Module administration page, available in the administrative toolbar under Modules (admin/modules) and depicted in Figure 2-24, is where Drupal provides the ability to turn on and off your website’s functionality. Related modules are grouped together within fieldsets called packages, 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 you’re troubleshooting problems. Finally, many modules also have links to their help pages, permissions, and configuration pages. This is very handy for getting to the meat of what a module does as soon as you turn it on.

The Module administration page

Figure 2-24. The Module administration page

You may switch modules 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. Some contributed modules may also require certain versions of other modules in order to be enabled.

One final handy page to be aware of is the administrative Index page at admin/index, shown in Figure 2-25. This has a full list of administrative pages grouped by the module to which they belong.

Viewing administrative tasks by module in the admin index

Figure 2-25. Viewing administrative tasks by module in the admin index

Finding and Installing Modules

Although core modules can provide the basics for your site, and can in some cases get you pretty far, the real power in Drupal comes from its vast array of community-contributed modules. You can browse and download all contributed modules from http://drupal.org/project/Modules, pictured in Figure 2-26.

The contributed modules browsing page at Drupal.org

Figure 2-26. The contributed modules browsing page at Drupal.org

Warning

Drupal 6.x modules are not compatible with Drupal 7.x, and vice versa. It’s very important to use the “Filter by compatibility” selection at the top of this screen to display modules only for the Drupal version that you are using. To display modules compatible with Drupal 7, change the drop-down to 7.x, and for Drupal 6–compatible modules, select 6.x.

Each module has its own project page on Drupal.org, as indicated in Figure 2-27. Here you’ll find a description and often a screenshot of the project, as well as information about its developers, what sort of bugs or features the project has, documentation links, and more. The main feature on this page is a table containing releases of the module that you may download. The version of the module you should download is the one in the Recommended Releases table in green, and whose version starts with “7.x-” (unless you’re using Drupal 6, in which case you’d look for the release that starts with “6.x-”, and so on). Visit http://drupal.org/documentation/version-info for much more information on Drupal’s version naming conventions.

The project page for the Login Destination module

Figure 2-27. The project page for the Login Destination module

Note

One of the most challenging aspects of using Drupal is determining which modules to use for a given task at hand. There are many modules that appear to cover similar ground, and the quality of modules can vary greatly. Appendix B is devoted entirely to the topic of tips and tricks for selecting the right modules for your project. But it’s not enough to find the modules you’re looking for; you also have to keep them up-to-date. We talk more about upgrading modules in Appendix A.

Once you’ve found your module, you need to get it into your Drupal site. There are two ways to do this in Drupal 7:

  1. The traditional manner is to download the module to your local drive, extract it, and then move it to your Drupal site’s sites/all/modules/ directory via SFTP or similar.

  2. Drupal 7 also has a feature called Update Manager that allows you to install and update modules directly from the web interface. We’ll walk through using this feature in Hands-On: Working with Modules.

Detailed instructions on how to install modules are available in the online Installation Guide documentation at http://drupal.org/documentation/install/modules-themes.

Removing Modules

If you decide that you no longer want to use a module, you have two choices:

Disable

Disable a module by unchecking the Enabled checkbox and saving the form. This action switches the module off temporarily, which can be useful for troubleshooting. You can re-enable the module at any time and your website will function exactly the same, as disabling a module does not remove the module’s data from your database. You may disable a module only if no other enabled modules require it.

Uninstall

Uninstalling a module removes the module permanently. To uninstall a module, you must first disable it, and then check off from the Uninstall tab (admin/build/modules/uninstall). Note that many but not all modules have an uninstall function.

Warning

Uninstalling a module will delete all data associated with that module, possibly including content on your website. Be very careful when using this option, and be sure to back up your database first. Note that uninstalling a module does not remove it from the filesystem; you still have to do this manually.

Hands-On: Working with Modules

The 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 a contributed module called Module Filter, which can be downloaded from Drupal.org.

You’ve probably noticed that scrolling in the Module administration page gets a little tedious, especially if you’re using the book’s source code, which comes bundled with dozens of contributed modules: prepare for lots of scrolling! Wouldn’t it be nice if there were a faster way to find the module you’re looking for? Luckily, there is: the Module Filter module, pictured in Figure 2-28. This module places a search box at the top of the modules page to help you quickly filter the list of modules by keyword, and optionally collapses all of the packages to vertical tabs to save screen real estate. This module does not come with core, so we will need to download it first.

The Module Filter module adds a search box to the modules page and arranges module packages into vertical tabs

Figure 2-28. The Module Filter module adds a search box to the modules page and arranges module packages into vertical tabs

  1. Go to the Module Filter project page. Look for its table of releases, pictured in Figure 2-29.

  2. Look for the “Recommended release” that starts with “7.x-” (at the time of writing, the latest recommended release, as pictured in Figure 2-29, is 7.x-1.6), right-click the “tar.gz” link, and copy the link location or address, depending on what your browser calls it. In this example, it should look something like http://ftp.drupal.org/files/projects/module_filter-7.x-1.6.tar.gz.

    The Module Filter module’s release table on Drupal.org

    Figure 2-29. The Module Filter module’s release table on Drupal.org

  3. In your Drupal site, navigate to the modules page at Modules (admin/modules) and click the “Install new module” link (admin/modules/install).

  4. In the form pictured in Figure 2-30, paste in the URL to the module’s tar.gz file copied in step 2. Click Install to proceed. You may be asked for your SFTP password if you are installing the module on a remote site.

    Installing a module through Drupal’s update manager

    Figure 2-30. Installing a module through Drupal’s update manager

  5. If all goes well, a progress bar will appear and then you’ll be taken to a confirmation page, as pictured in Figure 2-31. This means the module has been successfully uploaded and extracted to Drupal’s sites/all/modules directory.

    The “Update manager” screen if all is successful

    Figure 2-31. The “Update manager” screen if all is successful

  6. If these steps did not complete successfully, they may also be done manually. Download and extract the module .zip file from the Drupal.org project page, then place the module_filter folder into Drupal’s sites/all/modules folder. When you’re finished, the directory should look as pictured in Figure 2-32.

    Module Filter module files in the sites directory

    Figure 2-32. Module Filter module files in the sites directory

With the module files in place, we can now begin the next step: enabling the module and configuring its settings.

Note

From here on out, any hands-on sections that require contributed modules will assume that you’ve taken these steps, and that the module files are already in place in Drupal’s sites/all/modules directory. The book’s source code comes with all of the modules necessary to build the websites in future chapters already in place. If you want to follow along with the other chapters on your own Drupal website, you’ll need to install each required module in this same fashion. A quick reference list of the modules and themes used in each chapter is supplied in Appendix C.

  1. Return to the Module administration page at Modules (admin/modules) either by clicking the “Enable newly added modules” link or by navigating there by clicking the Modules link in the administrative toolbar.

  2. Find the Other package fieldset and check the Enabled checkbox next to the Module Filter module.

  3. Click the “Save configuration” button at the bottom of the form.

  4. Immediately, you’ll see the effects of this module, as pictured in Figure 2-28. The modules page is transformed, with a search box added and fieldsets turned into vertical tabs. As you type letters into the search box, you’ll see the list of modules below narrow to only those that match. Handy!

  5. Most modules offer additional configuration settings to allow for further customization, and Module Filter is no different. In the new search box, enter the text “modu” to reduce the list so that only Module Filter appears, and click the Configure link under the Operations column to discover the settings the module provides. Experiment with the settings (for example, uncheck the Tabs option) and observe how the Module page changes.

Now that we’ve seen how to install, enable, and configure modules, let’s delve into detail about how to control who has access to use them.

Spotlight: Access Control

One 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 administrator, 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. A role can be something like “administrator” or “sales team member.” Drupal comes with three roles by default—“anonymous user” (for all users who have not logged in), “authenticated user” (for all logged-in users), and “administrator” (which gets all permissions)—but you can create as many different roles as you want.

Permissions

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 “Administer modules” and “Post comments.” If a user does not have proper permissions to do something on the website, she’ll receive an “Access denied” error page when trying to access the given functionality.

Note

You can customize the “Access denied” and “Page not found” error pages by going to ConfigurationSystem“Site information” (admin/config/system/site-information).

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. Different access levels will correspond to roles and permissions in the system. For example, “content editor,” “forum moderator,” “customer,” and so on.

Configuring User Access

Controlling user access consists of three parts: (optionally) creating one or more roles to match the types of visitors your website needs to support, assigning permissions to those roles, and associating user accounts with those roles.

Under PeoplePermissionsRoles (admin/people/permissions/roles), pictured in Figure 2-33, you may create, edit, or remove roles, as well as reorder them with the drag-and-drop handles in order of escalated privileges. At this stage, there’s nothing more to a role than a name. Individual users may be assigned to roles either via their user edit page or from the administration page at People (admin/people). Both creating and assigning roles requires the “Administer permissions” permission, which is separate from the “Administer users” permission that gives access to the main People administration page.

Note

Clicking the “edit permissions” link next to a role on this screen will display the matrix of permissions for only that role. This feature can be useful if you need to set several permissions for only a single role.

The Roles administration page

Figure 2-33. The Roles administration page

At PeoplePermissions (admin/people/permissions), individual permissions may be assigned to roles, as shown in Figure 2-34. Access to this screen is controlled by the “Administer permissions” permission, so different users can take care of day-to-day user-related administrative tasks without requiring an escalation of their privileges in the system.

Warning

When you first create a role, it won’t be assigned any permissions beyond what all authenticated users receive. Administrators are initially responsible for defining permissions and assigning users to the new role. If you get bug reports about people not being able to do things you think that they should be able to do, always check the permissions page!

Often, permissions will have descriptions underneath them to provide more information about what they do. Additionally, modules that can impact website security will be labeled with “Warning: Give to trusted roles only; this permission has security implications.” This means that this permission should only be given to an administrator-level user, unless the full ramifications for that permission are fully understood.

Warning

Whenever you see “PHP” in a permission name, think very carefully about whether you trust each and every one of the people within a given role before you select it. A malicious user with PHP access can wreak all sorts of havoc, from deleting all of the content on your website to spamming all of your users, or potentially interfering with other applications outside of Drupal. Beware.

Note

All roles apart from “anonymous user” receive the permissions of “authenticated user” plus any other roles they’re assigned. In Figure 2-34, editors and administrators inherit the “View comments” permission because they are by nature logged in (authenticated users) in order to use the site. However, because “Administer comments and comment settings” is an elevated permission not given to authenticated users, it needs to be checked for both editors and administrators so that both roles receive the permission.

The Permissions administration page

Figure 2-34. The Permissions administration page

User Profiles

Each user has a special page in Drupal called the user profile. This is the page that you see when clicking the “My account” link after you have logged in. Other users might visit your user profile page by clicking your name next to a blog entry or comment you have authored on the site. By default, the user profile page lists some simple information about the account, such as the username and the length of time that the user has been registered on the site. However, additional fields may be added to a user profile and contributed modules may provide more information here, as shown in Figure 2-35. Users may change basic settings in their user profile, such as their password and their time zone, and other modules can add extra features here as well, such as a language selection or a field to upload a picture to be displayed alongside the user’s posts.

A user profile page on Drupal.org, with additional information provided by add-on modules

Figure 2-35. A user profile page on Drupal.org, with additional information provided by add-on modules

Account Settings

Under ConfigurationPeople“Account settings” (admin/config/people/accounts), there are many customizable user options, including:

  • Various registration options, including whether users may create accounts themselves or this function is restricted to administrators only

  • The exact text of various system emails sent from Drupal when, for example, a user registers, or when a user account is blocked

  • How to handle the data of a user if her account is canceled

  • Which role to use as the “administrator” role

  • Signature support, which allows users to enter in a small bit of text to be included at the end of any of their comments

  • Picture support, which allows users to upload an image or avatar that will be displayed next to any of their posts and comments

  • What extra fields are shown on the user profile, if any, and how they are displayed

Note

The ability to add arbitrary fields to user profiles is an important feature of Drupal 7, and will be covered in Chapter 3.

Warning

By default, registration to the site requires administrative approval, which is a basic protection measure so that test Drupal sites do not attract unwanted attention while in development mode. When you’re ready to make your site public and have real people sign up to it, make sure to toggle the “Who can register accounts?” setting to Visitors so your throngs of eager visitors can actually register accounts.

Handling Abusive Users

A community site of any reasonable size and popularity may eventually attract visitors with less-than-honorable intentions.

Administrators with the “Administer users” permission may change a user’s status to Blocked, which will prevent him from logging in. The blocked user then has only the rights of an anonymous user. User accounts may also be canceled, and you’ll be presented with a variety of options about how to handle the accounts and what to do with their content.

For more automated blocking, Drupal also provides the ability to block IP addresses, available at ConfigurationPeople“IP address blocking” (admin/config/people/ip-blocking), to help keep out repeat trolls, spammers, and the like. If you have the ability to block nefarious users from a firewall or web server level, however, that’s a much more scalable approach and keeps them out of other web applications you might have on the same server.

We talk more about people with nefarious intent in Spotlight: Content Moderation Tools.

Hands-On: Creating Roles and Users

Earlier, 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 freely 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 technically 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. Luckily, Drupal comes with an “administrator” role by default that does just the trick.

Note

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:

  1. Begin by creating an additional role for Mike and Jeanne. In the administrative toolbar, click on PeoplePermissionsRoles (admin/people/permissions/roles).

  2. Enter editor as a role name and click “Add role.”

  3. Because e is alphabetically after a, the “editor” role ends up at the end of the role list. However, the role’s level of permissions is actually between that of an “authenticated user” and an “administrator”; it will have more permissions than the former but less than the latter. Use the drag-and-drop arrows to move the “editor” role up one row so that it’s placed between “authenticated user” and “administrator” and click “Save order.” This will place the roles in the same order from left to right on the permission page, which will make things more intuitive.

  4. After you’ve set up roles, it’s always a good idea to set up some test users as well. Go back to People (admin/people) and click the “Add user” link (admin/people/create).

  5. Enter in the settings from Table 2-4 and Figure 2-36 and click “Create new account.”

    Table 2-4. Values for initial website users

    Setting

    Value

    Username

    jeanne

    Email address

    Password

    Your choice, but try to pick something secure; perhaps “Mom-0-Rama”

    Status

    Active (default)

    Roles

    Check:
    • authenticated user (default)

    • editor

    Notify user of new accountUnchecked (default)

    Note

    “Notify user of new account” is a handy feature on “real” Drupal sites, as it sends a quick email to the person to let him know his account was created, and provides instructions on how to log in. The exact email template used to do this, like all other user-related email templates, is configurable from ConfigurationPeople“Account settings” (admin/config/people/accounts).

  6. Repeat the previous step for Mike, and repeat it again for Goldie, but add her to both the “editor” and “administrator” roles.

  7. Also create a user called “customer,” but do not assign any special roles.

  8. When finished, your People administration screen should look like Figure 2-37.

    New user account form

    Figure 2-36. New user account form

    A listing of site users

    Figure 2-37. A listing of site users

Note

Technically, Goldie doesn’t need a user account of her own, because she can just keep using the User 1, or superuser, account. However, it’s best practice to create a unique user for everyone on the site, and to only use User 1 when the hugely elevated permissions are actually needed, like when first installing and building out your Drupal site.

Hands-On: Configuring Permissions

Now that we have roles and users in place, let’s assign some permissions to control who can do what on the site:

  1. In the administrative toolbar, go to PeoplePermissions (admin/people/permissions).

  2. This screen, as shown earlier in Figure 2-34, is massive, and there’s a lot to do here. We’ll cover this rather daunting page on a per-role basis.

  3. Anonymous users get the least amount of access on the site. They should really only be able to view and search content on the site, and post comments without bypassing the moderation queue. Check off the permissions in Table 2-5 for the “anonymous user” role.

    Table 2-5. Permissions for the anonymous user role

    ModulePermission
    Comment

    View comments (default)

    Comment

    Post comments

    FilterUse the Filtered HTML text format (default)
    NodeView published content (default)
    SearchUse search

    Warning

    Be very careful when assigning permissions to the anonymous user. These are the very definition of “untrusted” users. In addition to the general rule of avoiding any permission with “security implications” in the description, be aware that some permissions may behave erratically when assigned to the anonymous user role. For example, if the Node module’s “Article : Edit own content” permission is applied to the anonymous user role, this will actually allow all anonymous users to edit articles created by any other anonymous user! This occurs because all logged-out users share the same user ID (0). Once again, always make sure to test your access control to ensure that it’s working as you intended!

  4. Authenticated users should get all the permissions of anonymous users, plus a few others. For example, their comments should appear instantly on the site, rather than having to wait to be approved. We’ll also allow them to view the user profiles of other users on the site. Choose permissions for authenticated users according to Table 2-6.

    Table 2-6. Permissions for the authenticated user role

    ModulePermission
    Comment

    View comments (default)

    Comment

    Post comments (default)

    CommentSkip comment approval (default)
    FilterUse the Filtered HTML text format (default)
    NodeView published content (default)
    SearchUse search
    UserView user profiles

    Warning

    Remember that choosing a permission for authenticated users selects that permission for all logged-in users, regardless of other roles they might have. Always give authenticated users the lowest subset of permissions you’re comfortable giving all active users on the site.

  5. Next, we get to the real meat of our site’s access control: the “editor” role for Mike and Jeanne, our site’s primary users. We’ll want to give them some administrative control over the site, particularly as it relates to content management. This means providing permissions such as “Administer blocks” and “Administer comments and comment settings.” However, we’ll also want to hide the more advanced configuration settings from them, so as not to overwhelm them with settings, particularly if they could break the site by misconfiguring something. This means not granting access to permissions such as “Administer text formats and filters” or “Administer software updates.” Typically, avoid granting access to permissions with “security implications” in the description to inexperienced content editors, although there are some notable exceptions.

    One such exception is the Node module, which exposes two such permissions: “Bypass access control” and “Administer content.” “Administer content” is a handy shortcut permission, as it provides create, edit, and delete permissions to all content types in the system. In a case like Mom and Pop, Inc. where there are only two, well-known content creators, we can trust them with this level of permissions. We can also trust them with “Bypass access control,” a permission that allows the user to view all content on the site, even if it would normally be marked private. While this doesn’t apply in the case of Mom and Pop, Inc., other sites may be using a module such as Content Access or Organic Groups to hide content from certain users, and more caution may need to be exercised with this permission in that case.

    Finally, there are also a host of permissions around using Drupal’s administrative tools, such as “Use contextual links” and “Use the administration toolbar.” We’ll grant these to the “editor” role as well so that Mike and Jeanne can successfully administer the site going forward. One important permission to grant any editors on the site is the “Use the administration pages and help” permission from the System module. Without it, users will be unable to reach several sections of the administration panel, such as Structure, which holds block and menu configuration pages.

    Configure the permissions for the editor role as outlined in Table 2-7. Note that this list excludes the permissions assigned earlier for the “authenticated user” role, because those are already provided to those in the “editor” role.

    Table 2-7. Permissions for the editor role

    ModulePermission
    BlockAdminister blocks
    CommentAdminister comments and comment settings
    CommentEdit own comments
    Contextual linksUse contextual links
    DashboardView the administrative dashboard
    MenuAdminister menus and menu items
    NodeBypass content access control
    NodeAdminister content; this obviates the need for any of the individual content type permissions
    NodeAccess the content overview page
    NodeView own unpublished content
    NodeView content revisions
    NodeRevert content revisions
    NodeDelete content revisions
    OverlayAccess the administrative overlay
    PathCreate and edit URL aliases
    SearchUse advanced search
    SystemUse the administration pages and help
    SystemUse the site in maintenance mode
    SystemView the administration theme
    SystemView site reports
    ToolbarUse the administration toolbar
    UsersAdminister users
  1. We don’t need to provide a table for the administrator role; it automatically inherits all site permissions, which is as intended. However, it’s worth talking about a few permissions that we’ve deliberately kept restricted to administrators rather than editors.

    Filter module is one of the big places in Drupal with security implications, as the filters used in text formats determine what user input gets stripped out in content, comments, and similar. While Filtered HTML in its default configuration is safe, Full HTML access is extremely dangerous! In addition to the more benign, accidental things users might do with this permission—like leave off a closing </div> tag that completely destroys your site’s layout—more malicious and savvy users can embed cookie-stealing JavaScript and Flash code to gain control of an administrator account (or worse). Keep untrusted users to Filtered HTML only, and expand the list of allowed tags only after careful consideration of their effects.

    From both a security and site stability standpoint, it’s a good idea to restrict the “Administer modules,” “Administer software updates,” and “Administer permissions” permissions to only users who are tech-savvy enough to maintain the site themselves. These deal with code changes and privilege escalation, which are best left to someone familiar with Drupal and its modules.

    Finally, any permission with “PHP” in its name should always be restricted to the fewest number of users possible because such permissions are incredibly dangerous. In fact, you might even want to deselect these permissions from the “administrator” role in order to restrict it to User 1 only (of course, you’d also have to restrict “Administer permissions” to User 1 in that case so another administrator couldn’t just turn it on for herself).

  2. After double-checking the permissions one more time, click the “Save permissions” button to save your work.

Now it’s time for the final step: testing! Click “Log out” and notice that the toolbar disappears, there is no Navigation menu in the sidebar at all, and while you can view the contents of the site, if you try to go to a URL like /admin, you’ll receive an “Access denied” error.

  1. Log in as “jeanne.” You should have the ability to create content or administer the site.

  2. Log out and then log in as “customer.” You should be able to see the “My account” and “Log out” links in the upper-right corner, but that’s about it. Click on the article we created before, and leave a comment. Note that it shows up instantly.

  3. Now, log out and leave a comment as an anonymous user. You should receive the message, “Your comment has been queued for review by site administrators and will be published after approval.”

  4. When you’ve finished experimenting, log back in as the admin user account you created when you installed Drupal.

  5. If you’d like, approve the anonymous comment by going to the administrative toolbar and clicking ContentComments“Unapproved comments” (admin/content/comment/approval). Edit the comment, and read its contents. If it’s acceptable, expand the Administration fieldset at the top, change Status to Published, and save the form.

Note

Future chapters (and the book’s source code) will name the test users for each role “user,” “editor,” and “admin,” respectively, and give each account the password “oreilly.”

Spotlight: Content Moderation Tools

When you open the floodgates for your users to become active participants in content creation, one of the inevitable things that comes up is 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.

Automated Spam Detection

Mollom is a service started by Benjamin Schrauwen and Dries Buytaert, creator and project lead of Drupal. It automatically scans the content of your site comments (as well as nodes, the contact form, and multiple other places where user-generated content comes in) and, based on its analysis of millions of other blogs’ content, prevents obvious spam from even being posted to the website. Your website benefits from the collective intelligence of every other website that has a Mollom plug-in installed, and Mollom is compatible with many different content management systems and programming languages.

Mollom attempts to overcome shortcomings of traditional spam-trapping tools in the following ways:

  • Supports blocking not just comment spam, but also spam from the contact form, node forms (blog entries, forum topics, and so on), user registration and password request form, and others. This feature is not found in competing solutions, wherein you have to use one tool for handling comments and another for handling registration forms, which makes Mollom a one-stop solution.

  • Discerns between “spam” and “ham” and for those posts that are borderline, displays what’s known to web developers as a CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart), and is known to people like Mike and Jeanne as “those squiggly, hard-to-read characters you have to type in to get the darn form to go.” This test allows humans to proceed while blocking spam robots. CAPTCHAs are displayed as both an image and an audio file for maximum accessibility. Mollom thus helps to remove the need for moderation queues and eases moderation burden for administrators; spam is blocked before it hits the site at all.

  • Allows deletion not only of spam, but also of low-quality and off-topic content or violent and abusive content. Mollom also returns a quality score for each post, based on spelling, language, and punctuation, which you can use to maintain a certain level of professionalism on your site.

  • Leverages the power of OpenID by assigning a “reputation score” to OpenID accounts across all websites. This ensures that humans’ posts are let through instantly, while spammers’ posts are blocked across any site they attempt to post to via an OpenID account.

  • Generates graphs showing overall spam content, as pictured in Figure 2-38.

Example spam reporting from the Mollom module

Figure 2-38. Example spam reporting from the Mollom module

Mollom’s goal is to eliminate the need to do any manual intervention of content moderation, by passing the “gray area” validation to the posters themselves via the conditional CAPTCHA. And, unlike the CAPTCHA provided by most websites, users are only confronted by the scrambled character challenge if their post is “borderline”—not for every single form submission, unlike other solutions such as the CAPTCHA module.

The Mollom module is available from http://drupal.org/project/mollom, and you can obtain an API key by creating an account on http://mollom.com.

If you prefer to use other automated antispam tools such as Akismet or Defensio, another option is the AntiSpam module. While the AntiSpam module is not as popular in the Drupal world as Mollom, its ability to evaluate multiple external services to see which provides the best protection is a nice feature.

Manual Spam Prevention Tools

Automated tools are perfect for blocking obvious spam and robots, but what do you do to prevent trolls on your site from posting pornography or other offensive content? Some websites prefer a more hands-on approach, particularly if there are legal ramifications to offensive content appearing on the website even for a second.

Drupal core includes some basic content moderation tools, such as the ability to set any content type as “unpublished” by default (hiding it entirely from everyone but the original author and administrators), and revision control so that further edits can be “rolled back” to a version that was approved. But many Drupal sites set up their own custom moderation screens with tools like the Views and Flag modules, as well as the Revisioning module, a simple utility module that ensures that the approved version of a node stays published when subsequent edits are made.

Hands-On: Contact Form

Let’s tie together everything we’ve learned so far and get the contact form set up, as pictured in Figure 2-39. This will involve enabling the core Contact module, configuring its settings, and adding permissions.

A contact form for the website

Figure 2-39. A contact form for the website

Note

In addition to a site-wide contact form, the Contact module also optionally provides each user on the site with her own private contact form, which is accessible from her user profile. This is a useful means of allowing users to talk to one another without exposing their email addresses.

  1. First, enable the Contact module. In the administrative toolbar, go to Modules (admin/modules), and type con in the Module Filter search to quickly access the module’s row in the modules table. Enable it and click “Save configuration.”

  2. Next, we need to set up the contact form’s settings. Click the Configure link in the Contact module’s table row; or in the administrative toolbar, go to Structure“Contact form” (admin/structure/contact).

  3. Click the “Add category” (admin/structure/contact/add) link at the top. This screen shows a list of categories that users can choose from when using the contact form. On each category, you can choose which email address(es) will receive a copy of the mail, as well as whether an autoreply message should be sent to the user. By default, the Contact module has a category called “Website feedback,” which gets sent to the administrator email address.

    Let’s also add a new category for sales inquiries, so that customers can send in questions about Mom and Pop, Inc.’s products. We’ll also make this category selected by default, to help minimize the strain on Goldie’s inbox.

    Enter the category settings from Table 2-8, as pictured in Figure 2-40, and click Save.

    Table 2-8. Contact category settings

    Setting

    Value

    Category

    Sales inquiries

    Recipients

    (enter your email address)

    Auto-reply

    Thanks for sending us a sales inquiry! We will respond to you shortly.

    Weight

    0 (default)

    Selected

    Yes

    Settings for the website feedback contact form category

    Figure 2-40. Settings for the website feedback contact form category

  4. Next, we’ll want to add a link in the website navigation to the contact form for visitors.

    Some modules, such as the Contact module, conveniently provide us with a menu item all ready to use, though in the Contact module’s case 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.

    In the administrative toolbar, go to StructureMenusNavigation“list links” (admin/structure/menu/manage/navigation).

  5. Find the “Contact (disabled)” menu item in the list. Click its “edit” link.

  6. Enter the settings from Table 2-9 and click Save. This will enable the Contact link and move it from the Navigation sidebar up to the “Main menu” tabs, just after the Home and About Us links.

    Table 2-9. Contact menu item settings

    Setting

    Value

    Menu link title

    Contact

    Description

    Get in touch with us

    Enabled

    Checked

    Show as expanded

    Unchecked (default)

    Parent link

    <Main menu> (the very top selection)

    Weight

    10

  7. Finally, we need to configure permissions on the contact form so that visitors may use it. In the administrative toolbar, head to PeoplePermissions (admin/people/permissions) and enable the permissions listed in Table 2-10. We’ll give all users the ability to use the site-wide contact form, only authenticated users the ability to use each other’s personal contact forms, and Mike and Jeanne the ability to tweak the contact form categories. Click “Save permissions” when finished.

    Table 2-10. Permissions for the Contact module

    Permission: Contact

    anonymous user

    authenticated user

    editor

    administrator
    Administer contact forms and contact form settings  CheckedChecked
    Use the site-wide contact formCheckedCheckedCheckedChecked
    Use users’ personal contact forms Checked

    Checked

    Checked
  8. Finally, click the Contact link in your menu to view your shiny new contact form, as pictured in Figure 2-39!

Spotlight: Themes

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.

Themes are the Drupal method for controlling your site’s presentation. 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 comes with four themes to get you started:

  • Bartik

  • Seven

  • Garland

  • Stark

Finding a Theme

Most sites won’t be satisfied with the meager selection of themes that comes with Drupal core. Luckily, 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, as pictured in Figure 2-41.

Drupal.org’s themes listing, filtered by 7.x-compatible themes

Figure 2-41. Drupal.org’s themes listing, filtered by 7.x-compatible themes

Note

Many of the themes at the top of the “Most installed” list, including themes such as Zen and Fusion, are “base” themes. These themes intentionally provide very minimal styling, or even none at all, so that they can be used as a starting point for highly customized themes by those with CSS and PHP coding skills.

Unfortunately, detailing how to write a custom theme is outside the scope of this book, but if this is a topic that interests you, you can find more about it in the Drupal.org Theming Guide.

The quality of the themes in the Drupal.org 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.

Several companies, such as Top Notch Themes, offer premium, paid themes. These themes tend to be higher quality, are a bit more “bullet-proof,” and may allow for easier customization by administrators.

Theme Installation

Installing a theme requires almost exactly the same process as installing a module, as we saw in Hands-On: Working with Modules. You can either click the “Install new theme” link at the top of the Appearance page and walk through the installation wizard, or download the theme’s .zip or .tar.gz file from its Drupal.org project page and extract it into the sites/all/themes directory. Your new theme should appear on the Appearance (admin/appearance) administration page in your Drupal installation, as shown in Figure 2-42.

Note

As with modules, themes written for Drupal 6 are not compatible with Drupal 7 and vice versa.

Theme Configuration

Themes can be enabled and disabled from the Appearance page (admin/appearance) in the administrative toolbar, shown in Figure 2-42.

The Appearance administration page

Figure 2-42. The Appearance administration page

The Appearance page is divided into Enabled and Disabled themes. Enabled themes are exposed as options in interfaces such as the Block administration page, and other contributed modules can use enabled themes to make different parts of the site look unique. The theme marked “Default theme” (in this case, Bartik) is the one displayed on the frontend of the site. To set a different theme (such as Stark) as the frontend theme, click “Enable and set default” or “Set default,” as appropriate.

Note

Stark isn’t a pretty theme. It gets its name because it exposes Drupal’s “stark naked” markup with only the bare minimum of styling required to make sidebars show up in the right place. If you’re looking to make your own custom theme from scratch, Stark can be a useful starting point to determine what tags and styling you have to work with by default.

Drupal offers a number of configuration features that themes can take advantage of. There are two ways to configure themes. For global options (ones that you want to apply across all themes), select the Settings tab at Appearance (admin/appearance/settings). For settings specific to a single theme, or to configure settings that are only offered on a per-theme basis, select the Settings link next to any enabled theme (admin/appearance/settings/<theme_name>). The settings shown on this form will vary from theme to theme.

On these settings pages, you can toggle the display of many page elements, including the site logo, site name, site slogan, user pictures, and others, as shown in Figure 2-43. Sometimes, one or more of these checkboxes may be disabled by settings elsewhere in your installation. For example, if the Comment module is turned off, Drupal no longer lets you toggle the “User pictures in comments” and “User verification status in comments” settings.

The theme configuration page allows customization of which page elements are displayed

Figure 2-43. The theme configuration page allows customization of which page elements are displayed

Note

You can configure settings such as site name and site slogan at ConfigurationSystem“Site information” (admin/config/system/site-information).

The theme configuration page also allows administrators to upload their own site logo image and shortcut icon (also known as the favicon or bookmark icon, which appears in the browser’s address bar) or simply point to one elsewhere on their server. Note that in order to see these settings, you must first uncheck “Use the default.”

Some themes, such as the core Bartik and Garland themes, also take advantage of the Color module, which allows administrators to configure a theme’s color scheme using a handy JavaScript-based color picker. Figure 2-44 shows the Color module in action.

The Color module, supported in some themes, offers customization of the site’s colors

Figure 2-44. The Color module, supported in some themes, offers customization of the site’s colors

Blocks and Regions

It’s important to remember that block regions are defined by the theme, and different themes may offer different regions. If you have blocks assigned to a region in one theme and you switch to another theme that does not offer a region with the same name, these blocks could disappear from your site. After enabling a new theme, visit the Block administration page at StructureBlocks (admin/structure/block) and see what regions are available in your theme. You may need to reassign blocks to another region to take full advantage of the new theme.

Administration Theme Setting

By default, Drupal ships with the Seven theme—which sports a neutral, no-nonsense design—for use on administrative pages. This is to help you understand when you’re viewing the public frontend that your users will see and when you are in a backend, administrative context. It’s also possible to use a different theme as the administrative theme, or even to use the same theme for both the front- and backends of the site. You can choose an administrative theme at the bottom of the Appearance (admin/appearance) page. This theme will be used for all administration pages (those starting with “admin” in the URL path and also maintenance pages such as update.php), and optionally for content creation and editing pages as well. Figure 2-45 shows the Administration theme settings page.

The Administration theme settings page

Figure 2-45. The Administration theme settings page

Hands-On: Branding the Site

Now 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:

  1. In the administrative toolbar, head to the Appearance section (admin/appearance), and check that the first theme listed is Bartik and it’s denoted as “(default theme)” in the interface. If not, click the “Set default” link next to Bartik in order to make it the default theme. This change won’t appear to take effect until you exit the administrative interface and return to your public-facing website.

  2. Click the Settings tab (admin/appearance/settings) at the top of the page to configure the global settings, which apply to all themes.

  3. Under “Logo image settings,” uncheck “Use the default logo” to allow customization of the site logo.

  4. Upload the mom_and_pop_logo.png image in the assets/ch02-jumpstart folder in the book’s source code, and click “Save configuration.”

  5. Close out of the Overlay or click on the Home button in the administrative toolbar to return to your site’s frontend. You should now see the new logo appear in the upper-left corner, although—egad!—it looks absolutely horrendous on that blue background! Additionally, having both the text logo and the “Mom and Pop, Inc.” site name text feels pretty redundant. Let’s clean things up a bit.

  6. Return to the Appearance settings page by going to the administrative toolbar and clicking Appearance, and click the Settings link next to the Bartik theme (admin/appearance/settings/bartik). This allows you to access the Bartik-specific theme settings, which include an integrated color-picker from the Color module.

  7. Choose a color scheme that is pleasing to the eye and complements the logo. Be creative! Scroll down to see a preview of your colors while you work.

  8. When you’re happy with your color scheme results, under the Toggle Display fieldset, uncheck the “Site name” value so that only the logo appears, not the textual representation. Click “Save configuration” once you’re finished.

You should have a site that now boasts Mom and Pop, Inc.’s slick new logo, along with a color scheme that’s all their own, as shown in Figure 2-46.

Website bearing new logo and colors

Figure 2-46. Website bearing new logo and colors

Note

Interested in taking theme customization even further? Check out the Sweaver module, which provides a visual interface for styling themes. Sweaver will let you select page elements and change not only their colors, but also their background images, spacing, font styling, and more, all without writing a single line of code. And if you are code-savvy, there’s even a plug-in to allow you to enter custom CSS for page elements right from the browser.

Summary

This chapter provided an overview of Drupal’s major functionality by walking you through building a small website. We created some simple content and content types, we set up a contact form, and we worked on how to configure Drupal’s theme settings to customize a site to a particular look and feel. While this site is great for a start, we can add much more by expanding Drupal core with contributed modules, as we’ll show you throughout the rest of this book.

Here is a list of contributed modules we referenced in this chapter:

Here is a list of links that we referenced in this chapter:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset