Designing the menu item

Good Eatin' Goal: Design a content type to represent meals and drinks which are available at the restaurant.

Additional modules needed: CCK (

Basic steps

When you start designing your site it is a good idea to think about what types you will need, and design the types before building them. It is relatively easy to add new fields to a type, but if you do so you may need to modify all of the existing content, which can be extremely time-consuming.

Even seemingly simple types, such as an address, require some thought—depending on what addresses will be used. For example, if the addresses entered are only from the United States, typical fields are Street 1, Street 2, City, State, and Zip Code. If the address has to include international addresses, typical fields are Street 1, Street 2, City, State/Province, Zip/Postal Code, and Country. If the address is only for a single country, state, or city, you can eliminate or automatically fill out some of the fields, to make entering information more convenient for your editors and users. The types of validation that you do will also depend on what expected values can be entered. For example, for truly international sites, it is impractical to include every state or province in a drop-down list for users to select from. On the other hand, if you know that addresses are only within a specific country, giving a list of states or provinces is very easy.

Chapter 3

Step 1: Determine how the content type will be used

The first step in creating a new content type is deciding how the type will be used. You need to think about whether there will be a large or small number of entries, whether the information will be entered by experienced users, inexperienced users, or the general public. You also need to consider where the information will be displayed on the site, and in what format.

By collecting this information at the beginning, you can use it to guide future steps.

Step 2: Determine what fields need to be included

Think about what fields need to be included in the content type. You can do this in a number of ways:

• Use the fields from an existing paper form

• Use the fields from an existing back end system that the site will interface with

• Create fields based on the business process that you are adding to the site

• Brainstorm the possible values with a group of co-workers

• Look at example data to find commonalities, and then create a new field for each piece of common data

If you have tried several methods and still can't determine what the fields should be, you may want to try breaking the type into several separate but related types, or hiring a consultant to help you. Alternatively, you may have simply found a type that is not a good candidate to be created using CCK.

Each content type in Drupal automatically contains a field for a title, which is a single line of text, and a field for the description, which is a block of text. These fields can be renamed or hidden from view depending on your requirements. You will find that most content types that you create will use these two fields.

For our menu item, we will include the following fields:

• The name of the menu item (using the default title field)

• A description of the item (using the default body field)

• Information for with dietary concerns or allergies (gluten free, vegan, vegetarian, and so on)

• What meals the item is available for

Adding Products and Services

The course type of the item (appetizer, first course, second course, dinner, dessert, drink, and so on)

Whether the menu item is available only seasonally

When the menu item is available, if it is only available seasonally

Step 3: Determine what type each field should use and what validation should be done

After you have a list of the fields that you want to include in your new content type, you need to think about what information the field will contain, so that you can select an appropriate type for the field. You will want to consider whether the field contains basic textual information, numeric information, references to other content, dates, or some other type of information.

As you decide what types should be used, you should also consider how long each field should be, and whether it should be restricted to specific values, or if editors can enter anything they want in the field.

For our menu item, the fields will use the following types:

Field Type Validation


Text (single line)

Must be provided, no length requirements


Text (multiple lines)

Must be provided, text should be at least 10 words long


Numeric (decimal)

Must be a number greater than 0


Text free form list

This will be a free form list of key ingredients that visitors can search or select on.

Dietary Concerns

Text (free form list)

This will be a free-form list of possibilities that editors can add to as new allergens are added; it can be left blank if there are no allergens for the food


Text (simple list)

Must be filled out; possible values are Breakfast, Lunch, Dinner, Dessert, and Drinks. Multiple items can be included if it is available at more than one meal

Chapter 3

Field Type Validation

Course Type Text (simple list) Must be filled out; new values can be added by the editor. Default values are: appetizer, first course, second course, soup, salad, dessert, and drink

Must be filled out; default value is false

Can be left blank if Seasonal is false; can include month, date, and year

Can be left blank if Seasonal is false; can include month, date, and year

Seasonal Numeric (true/false)

Seasonal Start Date

Seasonal End Date

Step 4: Determine how the fields should be displayed when the user edits them

When an editor creates or edits your new content type, you can make things easier for them by selecting a meaningful control that they use to edit the field. By default, CCK only gives you a simple text field that you can use to enter information. By enabling the Option Widgets module, you get a selection list, option buttons, and checkboxes. Using these optional controls makes selection faster, and easier to validate.

Step 5: Determine who will be viewing and editing the content type

In this final step, you need to consider who will enter the content and who will view it. This will help you to determine which permissions are to be added for each field. If you find that there are several different permissions needed, you may need to explore the Content Permissions module which is included in the Core CCK installation. This module allows you to set permissions for each individual field independently.

Our menu item type does not need specific permissions for each field.

Was this article helpful?

0 0

Post a comment