CCK Module Basics
Content Construction Kit (CCK) is one the most important and at the same time most mystifying features of the Drupal platform. In this drop I'll provide a high level overview explanation of CCK and why you might want to use it on your site.
What is CCK?
CCK is a contributed module that allows you to:
- Add fields to an existing Drupal content type
- Create new custom content types
Drupal Content Types
It's important to understand a bit about Drupal content types. Drupal comes standard with blog, page and story content types. The main difference between these content types is the way they are organized by the system.
- Blogs are associated with a particular user and will be listed at 'http://www.yoursite.com/blog' which shows all blog posts by all users. Blogs will also be listed on page that shows only posts by a particular user. The url for those pages may be something like 'http://www.yoursite.com/blogs/[username]'.
- Pages will simply have a url " and not show up in any lists unless you take some sort of action to do add them to a list.
- Stories are like pages except that they are automatically promoted to the front page.
The common thread across these three types of content types is that by default they contain two fields called Title and Body. But what if you want to expand a content type to add more fields? That's where CCK comes in.
CCK allows you to add one or more fields to an existing content type. There are a number of reasons why you might want to do that. You could add fields to improve your workflow. If you're publishing video you might want to add a link to the video each time you post. Adding a field that is required when you submit ensures that you won't forget to add the link. See my post Adding Fields With CCK for an example.
You could also add a field to make it easier for you to organize or theme your content later. When a piece of information is entered into the body field you can't really sort that piece of information or use it if you want to create a list using views. But once a piece of information has it's own field you have much more flexibility. Using the video publishing as an example once again you might add a field that displays the duration of a video that is linked to a post.
Creating New Content Types
If you want ultimate flexibility in customizing your content types then you can use CCK to create a whole new content type that meets your specifications. Imagine that you want to be able to add information about your favorite DVDs to your Drupal site. The title and body fields probably won't meet your needs. You might want fields that list the Director of the movie, the top stars, release date, rating, an image, a link to the trailer and more. CCK was tailor made for things like this.
How Does CCK Work?
Many people are confused about how exactly to put CCK to use on their own website. You get started by downloading the module from http://drupal.org/project/cck but you will likely have to do more. The power of CCK is in the types of fields that it allows you to add to a content type. The contributed module includes several standard fields (like text and node reference) included but many of the fields you would want to add to your content type must be downloaded and enabled separately.
Here are some additional fields that are listed on the CCK module page on Drupal.org:
- Computed field: lets you add a PHP-driven "computed field" to CCK node types
- Date: creates an ISO or unix timestamp date field
- Email: validated email field
- Image field: an image field
- Link: a URL field
There are many other fields that you could use to customize your content type. These can be found in the CCK modules section on Drupal.org. Some of the interesting fields that you might want to add are listen below.
Your new content type is basically a list of fields that are ordered a certain way. Creating a new content type and adding fields is only part of the work you'll need to do in order to make CCK work for you on your Drupal site. Each field that you add has settings that must be attended to. You may also be concerned with how the new content type is displayed when you publish a node. The Contemplate module allows you to adjust the layout and customize the appearance of content types. If the content type you have created is brand new then you will need to use the Views module to create a page, block or RSS feed for the content.
Another thing to consider when creating a new content type is the path to the nodes that you create. By default content created on your Drupal site will have a path that looks something like 'http://www.yoursite.com/node/24'. If you're submitting the DVD content type that I mentioned above you might want to the path to be something like 'http://www.yoursite.com/dvd/[movie-title]. That's why I highly recommend the PathAuto module for automatic node url creation.
These are screenshots that show what CCK features look like in the adminstration section of this site.