Drupal supports many different ways to create and manage content. In Drupal, all content types derive from something that is called a node, which just provides you with a title and body field. In fact if you do not know what a node is then you shouldn’t read on any further and get more acquainted with Drupal before delving into more complex topics.
As you probably know, Drupal comes with several content types to begin with, namely the story and page types. These are useful if you are building a simple website with a blog and some extraneous pages. Over the past several months at Codesta we have worked on several different projects which required the use of our own custom content types. We discovered that Drupal can be a maze when it comes to selecting a suitable content type which extends the basic Drupal ‘node’ concept. We have dabbled using CCK (Content Construction Kit) to create content types programmatically and would like to share some of our findings. In this Part I will provide a general overview of the variety of content and node types, including some of the high level benefits and drawbacks to each method. In future articles I will flesh out the details of each. You should have a good understanding of the purpose and function of the CCK to get the most out of this overview.
Types of Content Implementations:
a) Create your own.
b) Use the CCK to create your content types.
c) Using a mixture of CCK and your own modules.
d) Programmatically create a field for use in a CCK.
A) Create your own module.
Overview:
This method involves using Drupal’s hook system to tell the framework that you’ve added a new content type. You need to take care of creating any new tables in the database that the content type will use to store data for the content type.
Discussion:
This method gives you the most flexibility, but it also usually requires more time to implement. You have full control over the database schema and the relationships they have over other content types or tables. In light of this you are responsible for the validation of input, creation of the input forms, and the database queries to update the database.
B) Use the CCK to create your content types.
Overview:
Through the CCK module you can create new content types and connect them to views quickly and readily.
Discussion:
Table structures are automatically created so there is no need to worry about database management. Integration with views makes it easy to display lists of content in many different ways. The CCK also takes care of validation of form elements for you.
C) Using a mixture of both CCK and your own modules.
Overview:
Sometimes it may be the best option to integrate a node module with a CCK content type. This gives you the benefit of CCK where you do not need to worry about the forms and database queries while at the same time leverages the flexibility of creating your own module. This involves configuring your content type through CCK and creating a module with the same name as the content type.
Discussion:
We found it necessary when working with client requests for dynamically generated forms in Drupal to use a mixture of CCK and own node module. This required the AHAH module (which provides the framework to create new form elements on the client side while talking to the Drupal back end to keep track of these new elements). The reason we didn’t implement the content type in a custom node module was that only one field needed to be dynamically populated. All remaining fields were good as they were, so we wanted to leverage CCK to rapidly develop the content type.
D) Programmatically creating a new field that can be then used through the CCK module interface.
Overview:
The CCK allows you to create reusable ‘field types’ that can be used with any CCK content type. For example, perhaps you would want a field in your content type that stores the graduation date and major for a student. You would like these items to be grouped together, and you already have a CCK content type built for students. You can use the CCK API to create the new field and add to any it to you student CCK content type.
Discussion:
In our case we needed an enhanced predictive text box field that queried several different tables. We also knew that there would be several slight variations of the same field. We already had a CCK content type and it did not make sense to write a node module for it, so we choose to write an enhanced predictive textbox field to be used with CCK. Now we can use this field in the future in other CCK content types without writing a single line of code.
We have briefly discussed several different methods for extending the content that Drupal natively supports, in the coming weeks we will go into more depth with each method.