Drupal 6 custom content type

Notes on custom content types in Drupal 6, mainly about the modules used to create custom content types.

Index

Initial setup

Either create a module or use the Content Construction Kit (CCK)

Create new content-type for Drupal 6.x

To get rid of a default field, like the body, edit the type’s submission form settings and set the field label to blank.

Bug alert! There is a bug in CCK / Views whereby deleting a CCK field from a content type will result in error messages in the View UI when the field is being used by a view. You must remove a field from all views before deleting it from a content type.

CCK

Also see: Adding Fields With CCK

  1. Install module and enable all submodules.
  2. Create a new content type from Administer -> Content management -> Content types.
  3. Use ‘Manage fields’ option to define fields and field groups for the new content type.
  4. With the CCK Content Permissions “sub”-module enabled, for each field you add to the new content type, you need to set the edit and view permission in the ‘content_permissions module’ section of Administer -> User management -> Permissions.
  5. To remove the body field from a new content type, edit the type and in the ‘Submission form settings’ section blank out the ‘Body field label’ field.
  6. Title can not be removed, but the label can be changed in the ‘Submission form settings’ section mentioned above.
  7. The appearance of custom fields in a content type’s displays (e.g. Basic, RSS, Token) can be configured via Administer -> Content management -> Content types, edit type, ‘Display fields’ tab.

CCK fields

There are many modules to add new CCK field types. Here are some of those I use often…

Date

Date

  1. Install the module and enable Date, Date API, Date Timezone, Date Popup.

ImageField

ImageField

Requires FileField

  1. Install as normal.
  2. Give role permission to ‘view image field’ via Administer -> User mangement -> Permissions.
  3. Configure settings via Administer -> Site configuration -> File system, File uploads and Image toolkit.
  4. To have a view display the image, choose ‘Content: Image’ as a view field and configure it to have format ‘Image’ (via Administer -> Site building -> Views).

Note that uploading an image may not work if you have the devel module enabled.

Conditional Fields

Conditional Fields

  1. Install as normal.
  2. Administer -> Site building -> Content types, ‘manage fields’ for a type.
  3. There should be a new ‘Conditional field settings’ section when you configure a field, which allows you to set which value of another field will trigger the display of the field you’re configuring.
  4. Show/hide animation settings can be found via ‘Conditional fields’ tab.

Link

For link fields. It can validate the link, use tokens to set its title (e.g. to the title of the node) and doesn’t mind if http:// is entered or not.

Views

  1. Install modules and enable all submodules.
  2. Administer -> Site building -> Views -> Add tab to create a new view.
  3. Add a new ‘Page’ display and select it.
  4. For each set of attributes, click an attribute to change it (selecting Override to avoid changing defaults), click the cog icon to configure it and click the plus icon to add another attribute.
  5. Basic settings -> Style to change view display, e.g. Table.
  6. Add a filter to reduce content set. E.g. Node:Type is one of Page.
  7. Add fields to display. E.g. Node:Title and Node:Body. Use Content group for CCK fields.
  8. Other useful option is Use Ajax: Yes.
  9. Define a path in Path and Menu parts of Page section.
  10. Save the view.

A useful feature is the abilit to rewrite the markup generated by a field. For example, you can create a linked image block (e.g. for ads) by doing the following with CCK/Views:

  1. Create a new content type via CCK, giving it an image field (via the ImageUpload views module) and a text field for a URL. Note that ImageUpload will give the image a couple of other fields, e.g. alt text, description and title, depending on how it is configured.
  2. Create a view, set to a Block display, with Row style ‘Fields’.
  3. Add the CCK image and URL fields - ‘Content: Image’ and ‘Content: URL’, though the names may differ depending on what you named the fields when you created them.
  4. Add the other image “sub”-fields that ImageUpload associated with the image, by choosing ‘Content: Image (field_image) - data’ and selecting the appropriate data key, e.g. alt text, description or title.
  5. Set the format of the image field to ‘URL to file’.
  6. Exclude all fields from display except for image field.
  7. Reorder the fields so that the image field is last.

    Content: URL Plain text
    Content: Image - data description
    Content: Image - data title
    Content: Image - data alt
    Content: Image URL to file
    
  8. Configure the image field and set it to ‘Rewrite the output of this field’, using the following markup to makes use of the replacement patterns we have available (by putting all other non-displaying fields first):

    <a href="[field_url_value]" target="_blank" title="[field_image_data_1]"><img src="[field_image_fid]" alt="[field_image_data_2]"/></a>
    
  9. Set the block to display as normal. It should show the image as a link to the URL.

Note that I have written a module called ‘Ajax Block’ which can be used to refresh a block via AJAX, hence achieving rotating images/ads/news etc.

The Access method in Basic Settings section only controls access to the view, not the items in the view. The View Own module can restrict the display of items in a view to those created by the current user.

How to sort an ID field

Some fields only store the ID of some other content, preventing them being sorted. For example, if you had a content type with a field that referenced a different content type. To get around this problem:

  1. Create a relationship for the referenced content type.
  2. The fields for the referenced content type should now be available.
  3. Add one of those fields and it should be sortable.

See HOWTO: Views 2 Relationships screencast.

Adding a view to a menu

Views (at least page views) provide config so you can add them to a menu. However, they only allow you to create an item at the top level of a menu and the functionality seems buggy in that the menu item sometimes disappears when you later edit the view.

Better to give the view a page and create a menu item via Administer -> Site building -> Menus.

Views Bonus Pack

Views Bonus Pack

Provides a number of extras for the views module - data export, panels for layout, lineage nest taxonomy, audio playlists (last two not complete in Drupal 6).

For CSV export of views…

  1. Install module as normal and enable the ‘Bonus: Views Export’ “submodule”.
  2. Administer -> Site building -> Views.
  3. Create new view and set up as normal.
  4. Give it a new display of type ‘feed’.
  5. Change its style to ‘CSV file’.
  6. Give it a path.
  7. Save, then view the path and you’ll get a download for the CSV.

SWF Tools

SWF Tools

Embed media players for attachements.

  1. Install module as normal, enabling ‘SWF Tools’.
  2. Administer -> Site configuration -> Input formats.
  3. Enable ‘SWF Tools filter’ for whichever input formats you use.
  4. Create a page and with an mp3 attachment (e.g. mpthreetest.mp3).
  5. Add the following to the page to include the player: [swf file=”mpthreetest.mp3”]
  6. There are many more config options available, e.g. third party players for all kinds of media types. See http://drupal.org/node/303203

Last modified: 16/11/2011 Tags: ,

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top