«

»

Understanding Drupal Content Types & Fields (Pt 2 of Content Management with Drupal)

This article is the second in our serialization of several chapters from the Drupal 7 Bible. In this installment in the series, we introduce the default Drupal content types and the related fields.
-ed

 

As mentioned in the previous installment, all content in Drupal is based on the Node module; this is why Drupal content items are often called nodes. A content item also must be of a specific type. Articles, blog posts, and pages are examples of Drupal content types. You define content types by associating one or more fields with a unique type name.

When you create a new piece of content in Drupal, the first thing you do is select the type of content to create and then fill out a Web form associated with that type (which is, by and large, the act of putting data into Drupal fields), and then you save it.

Drupal Fields stand out as a new and important architectural concept in Drupal 7. They are containers that represent the smallest unit of content in the system. These containers are tied together to construct different types of content in the system.

In concrete terms, the Drupal article content type contains a title element and a body element. In this case, the title element is inherited from the node module, and the body is an associated Drupal field called body.

Here is another way of thinking about it:

Node Module + A Unique Name + One or More Fields = A Content Type

Discovering the default content types

The standard installation of Drupal 7 comes with two content types enabled: the Article and the Page. You can access four more default content types by enabling other core modules. With the six default content types, you can create a broad variety of content. They are sufficient for many typical Web site scenarios and can be adapted to work for many others.

Drupal has six default content types:

  • Article
  • Blog entry
  • Book page
  • Forum topic
  • Page
  • Poll

Introducing articles

Drupal 7 content article type in action

A screenshot of the www.cmswire.com homepage with news content sorted in reverse chronological order

The article type is a default content type in the standard Drupal 7 release. It is a flexible type of content, but is generally used for time-sensitive information. This class of content is broad, but the general rule is that the content’s relative value tends to decrease over time.

Example usage scenarios for the article content type include the following:

  • News articles
  • Knowledgebase articles
  • Press releases

These are all examples of time sensitive content; they have a moment of peak value and then a descent toward lesser value. This pattern of content value is reflected in the way you manage content of this type. For example, we see a time-sensitive management pattern in the reverse chronological sorting of most news Web sites’ content: Specifically, the most recently published content is at the top of the page, while the oldest content is often buried in the archives, if present at all. Figure 10.1 shows a Web site with news items sorted in reverse chronological order.

By adding or removing fields, you can modify the article content type to suit your needs. Alternatively, you can create your own time-sensitive content types as you see fit.

Introducing blog entries

Drupal’s core Blog module supports the creation of one or more blogs in your Web site, including multi-user blogs. After you enable it, a new content type called Blog entry is available for use and a host of blog-like features are available to you (see Chapter 16 for details). This content type is similar to the article type in that it is flexible and most often used for time-sensitive content.

Example usage scenarios for the blog entry content type include the following:

  • Personal blog posts
  • Organizational news
  • Project updates

Introducing book pages

You can use Drupal’s core Book module to create hierarchical bodies of content. The module is disabled by default, but after you enable it, a new content type called Book page is available for use.

This content type is quite specific in its purpose. It is also a bit of an oddball; we don’t often think of books and Web sites together, that is, unless we’re in the process of buying books. To clarify the book page idea, keep in mind that this content type is used for information that is structured in multiple levels and benefits from the automatic generation of its navigational elements.

A Drupal book is like a real book; it can have pages, sections, subsections, and so on. When creating a new book page item, you choose where in the book hierarchy the item will be located. And later, you can move pages around in the hierarchy as you see fit.

Example usage scenarios for the book page content type include the following:

  • Lists of frequently asked questions (FAQs)
  • Online instruction manuals
  • A city guide or other resource guide

Introducing forum topics

You can use Drupal’s core Forum module to create threaded discussions, similar to what you see on many community or bulletin board Web sites. The module is disabled by default, but after you enable it, a new content type called Forum topic is available for use.

Example usage scenarios for the Forum topic content type include the following:

  • Community discussions
  • Product support forums
  • Project management discussions

Introducing pages

The page concept is as old as the Web itself. You see home pages, about pages, policy pages, and more every day. The unifying theme is that pages tend to be self-contained, static, and unlike time-sensitive articles, they tend to have a long lifetime.

The page content type is part of the default Drupal release and is made up of a title field, a body field, and a number of metadata fields that the system uses for content presentation and organization.

Pages often contain static content—content that rarely changes and generally maintains its position of importance in your Web site. In terms of content type structure, pages and articles are quite similar, but pages have fewer content fields.

Introducing polls

The core Drupal Poll module enables you to add polls to your Web site. The Poll module is disabled by default, but after you enable it, a new content type called Poll is available for use.

Polls have a question field and then two or more response option fields. You can also optionally set the duration of time that the poll will remain active in your site.

Example uses scenarios for the Poll content type include:

  • Running opinion polls
  • Taking a vote or holding an election
  • Collecting statistics about your Web site’s community

Creating content types

The default Drupal admin system provides you with browser-based tools for creating new content types. As a user with the Administer content types permission, you can quickly define new content types and make them available to authors.

Just because you can create new content types does not mean that you should. When you add more content types to your system, you potentially make it more complicated for administrators to maintain and more complicated for authors to understand. The addition of content types also can make your presentation logic more complicated.

Simplicity is golden when it comes to implementing a CMS. You should think carefully about the justifications for new content types; you may be able to achieve your goals by using content creation controls, rules, views, or other Drupal functionality.

The process of creating a new content type involves defining a name for the content type, setting the default content item options, and then adding one or more fields. When you add a field, you must specify the field’s data type, which in turn defines what kind of content each field can hold. The available field data types are described in Table 10.1.

Contributed modules like the Date module allow you to add more data types to your Drupal system.

 

Drupal 7 Field Data Types

Data Type Description
Boolean A binary value (such as on/off, true/false, yes/no and so on)
Decimal A numeric decimal value with configurable precision and scale (such as 5.25 or 3.14159265). Maximum and minimum values are dependent on the server platform.
File A Drupal File item
Float A numeric floating point value (such as 5.25). Maximum and minimum values are dependent on the server platform.
Image A Drupal Image item
Integer A numeric integer value (such as -35 or 35). Maximum and minimum values are dependent on the server platform.
List A list of key/value options where the key is an alias for the position of the value (e.g., 0=First option; 1=Second option)
List (numeric) A list of key/value options where the key has a numeric significance (e.g., 1=1 Day; 7=1 Week)
List (text) A list of key/value options where the key has a textual significance (such as CA=California; NY=New York)
Long text A long string value (no theoretical limit)
Long text and summary A long string value (no theoretical limit) with an optional summary string value
Taxonomy term A value from a Drupal Taxonomy vocabulary
Text A string value with a maximum length of 255 characters
By default, newly created content types have a title and a body field. You can remove the body field if you like. However, you cannot remove the title field because that is inherited from the underlying Node module.

Drupal 7 add content type form

The standard content item option set tabs displayed

 

The Drupal 7 admin screen displays the Add content type Web form with the standard content item option set tabs displayed.

The fields in the Add content type page are divided into two groups. At the top of the page are the fields needed to identify and describe the new content type. At the bottom of the page are the standard content item options.

These controls are related to the content type’s identity and description:

  • Name: Type the unique name of the content type into this field. This appears to content creators when they select the type of content to author. The value should begin with a capital letter and can contain only letters, numbers, and spaces. This is a required field.
  • Description: Type the description of the content type into this field. The description field is optional, but if you provide it, it is displayed on the Add new content page and visible to all authors, so it’s a good idea to provide a meaningful value.

The standard content item options are collected on individual tabs, divided into five option sets. These are the option sets:

  • Submission form settings: These items control the default look and feel of the Web form used to create or edit content items. Here you can customize the labels for the Title and Body fields, control content preview requirements, and provide help text for guiding the authoring process.
  • Publishing options: These items provide the default values that control if the content is published automatically when first saved, if it appears on the homepage when first published, if it is sticky at the top of lists once published, and whether a new node revision is created when changes are saved.
  • Display settings: These settings affect the presentation of the published content item. Here you can choose whether to display the author name and the publish date of the content, and you can control the length of the trimmed version of the content.
  • Comment settings: Use this option set to control how comments behave for this content type. Enable or disable comment threading with the first check box. Limit the number of comments per page with the select list. Control commenting status by setting comment to Open, Closed, or Hidden. You also can control the comment form behavior by enabling or disabling the comment title field and choosing whether the comment form is shown on a separate page. The comment preview settings allow you to disable comment previews, make them optional, or make them required.
  • Menu settings: Use this option set to control the menu setting choices present when authoring content of this type. Here you can set which menus are available to the author and assign the default parent item (in the menu hierarchy) for content of this type.

To illustrate the process of creating a content type, I create an example type called Test Type 01. Later, you can delete this content type from the system. Follow these steps to create the new content type:

1. Log into your site as an administrator.
The login landing page loads in your browser.

2. Select the Structure option from the main admin menu.
The Structure page loads in your browser.

3. Click the Content types link in the Structure page.
The list of current content types loads in your browser.

4. Click the Add content type link.
The Add content type Web form loads in your browser.

5. Enter a name for the new content type in the Name text box of the Web form.
For this example, use the name “Test Type 01.”

6. Click the Save content type button at the bottom of the page.
If you are successful, a confirmation message is displayed at the top of the page.

In the next sections, I discuss editing and deleting existing content types.

 

//END of Part 2

 

the drupal 7 bibleThis article is the second in a series. The content in this article comes from Chapter 10 “Content Management with Drupal” of the Drupal 7 Bible (Wiley & Sons). The Drupal 7 Bible is authored by Ric Shreves & Brice Dunwoodie. The book provides a comprehensive look at building and maintaining a website using version 7 of the Drupal open source content management system. You can learn more by visiting the Drupal 7 Bible page on this website.
 
 

About the author

Ric Shreves

Ric is an author and consultant who specializes in open source content management systems and in digital marketing. He's one of the founding partners of water&stone (www.waterandstone.com). He's also the author of the Joomla! Bible, the Drupal 7 Bible, the Ubuntu Visual Blueprint and the Drupal Themes series.

Leave a Reply

Your email address will not be published. Required fields are marked *


3 + one =

Notify me of followup comments via e-mail. You can also subscribe without commenting.