5 min read

Views module provide administrators with the means to modify how Drupal displays lists of content, and CCK exposes its fields to the Views module, making them perfect partners when it comes to creating custom content and then displaying that content in a highly configurable manner. At the time of writing, Views is not available for Drupal 6 (although the module is being actively developed and should hopefully be ready by the time you read this) so it is left as an exercise to download and install it, and create at least one new View, utilizing fields created in the following sections.

Installing CCK

CCK is available, so go ahead and download the latest version and extract the file to your modules folder. CCK adds its own section to the Modules page under Site building:

Building Powerful and Robust Websites with Drupal 6

There are a number of interdependent sections for this module, but all of them rely on the first option, Content, so go ahead and enable this first. We are going to look over all the features provided by CCK, by default, in this section. So go ahead and enable those modules that rely only on Content. With that done, enable the remaining options so that you end up with everything working, like this:

Building Powerful and Robust Websites with Drupal 6

Notice that some of the options are disabled to prevent us from inadvertently disabling an option that is required by something else. If, for example, you wish to disable Text, then disable Node Reference and User Reference first.

Working with CCK

With all the options enabled, we can now go ahead and create a new content type. Actually, it is possible to create new content types without the use of CCK, it’s just that the new content types will look pretty much like the standard content types already available, because there are no really interesting fields to add.

Head over to Content types under Content management and select the Add content type field to bring up the following page:

Building Powerful and Robust Websites with Drupal 6

The identification section is pretty straightforward. You can go ahead and fill in whatever new content settings are appropriate. Of special interest is the Submission form settings below this that allows you to decide whether the default Title and Body fields should be changed or even retained (in the case of the Body field):

Building Powerful and Robust Websites with Drupal 6

In the case of the Endangered Species content type, it doesn’t really make sense to have a species Title, rather a Common name makes more sense. Leaving the Body field label blank will cause this field to be omitted completely in the event that it is not suitable for the type of content you have in mind.

You may have noticed that there are several additional tabs to the right of Add content type tab that provide additional functionality. These options are discussed a little later on in this section. So for now, go ahead and fill out the Name, Type, and Description fields and click Save content type to add this to the default list:

Building Powerful and Robust Websites with Drupal 6

We are now ready to begin customizing this new type utilizing whatever options are available—depending on what is or is not enabled. It is possible to customize any type that is available on Drupal, including the default ones like Blog entry or Poll, but to begin with it is best to leave these alone.

To begin working on the new content type, click on edit in the Endangered Species row. We can now look at the various aspects of working with content types, beginning with…

Adding Fields

Select the Add field tab to bring up the following page:

Building Powerful and Robust Websites with Drupal 6

This dialog allows you to specify the new field’s machine readable name and then select what type of input it is going to be.

Presently, only the Create new field section is displayed on this page, because we have yet to add new fields. Once there is at least one custom field available, this page will have an additional section allowing existing fields to be added directly from any content type (you can come back here once there are a few saved fields):

Building Powerful and Robust Websites with Drupal 6

Regardless, the Create new field list presently comprises of the following options:

  • Node Reference – Allows the poster to reference another node using its ID value
  • Integer, Decimal, Float – Allows posters to store numbers in various formats
  • Text – Allows posters to enter content
  • User Reference – Allows posters to reference other users.

Remember that this list is subject to change, depending on whether you disable various components of the default package, for example, Node Reference or User Reference, or include additional modules that add field types such as Date or Fivestar.

Each value type comes with a set of options for how that data should be entered. Looking at the Integer type, we can see that users can be prompted for an integer with a Text Field, Select list, Check boxes, and radio buttons—in this case, the Select list is going to be used.

Be careful about how information is stored—it is important to be efficient. For example, don’t store information as text when there is only a certain number of options available, instead, store them as a number and provide the right input type to display the various options appropriately.

To demonstrate this point, consider that at the moment, the numbers_in_wild field is set as an integer with the Select list input type. We are not going to provide a select list of every possible integer, but we are going to represent a range of numbers with an integer. For example, the value 1 will correspond to the range 1-10, 2 will correspond to 11-100, and so on.

With the new field created, the configuration page for this field (Click on configure in the Operations column of the Manage fields page) now displays the current settings available. To begin with, the options in the Endangered Species settings are not of much interest as we have not specified what data this field will hold. To do this, scroll down the page to the Global settings section. From here, you can decide on how the data will be presented to the user and whether or not the field itself will be compulsory or not:

Along with the Allowed values list used to input key-value pairs, there are a few other settings that may be of use, depending on what data the field should capture. Minimum and Maximum values along with Suffix and Prefix values allow for some minor input validation, as well as some useful display properties like currency denominations or physical units of measurement.

LEAVE A REPLY

Please enter your comment!
Please enter your name here