Intro to CCK
Custom Content Kit (CCK) allows us to add additional fields to content types in Drupal, giving us much richer information about our content.
Today we'll create a mini ERF using CCK.
NOTE: In this tutorial I mostly use the path to the admin areas. You can just copy and past them after site url in the location bar: http://ucblibrary3.berkeley.edu:8086/tdennis/admin/content/types.
Drupal Core Content Types
Out of the box Drupal comes with two content types (go to admin/content/types):
- page
- story
Each type has a title & body field.
Now, lets add a new content type:
- Add content type button
- Name: eResource
- Type: eresource (this has to be machine readable--no spaces -- use only lowercase letters, numbers, and underscores)
- Description: Article databases or other electronic resources available to the UC Berkeley student, staff & faculty. (or make something up)
- Under Submission form settings, change body to description and leave title as is. Note: You can hide body altogether by leaving it blank.
- Under workflow settings published by default, promote to front page
- Save and now create an eResource record. Use the ERF if you want something real.
Limitations of Core Drupal for Content Types
In Drupal core there are limited options to add metadata to content types. We can add a taxonomy to the Content Type, but beyond that there's not much else.
Let's go ahead and add a taxonomy vocabulary to the eResource type:
- Go to admin/content/taxonomy/list and Add vocabulary
- Vocabulary name: Tags
- Adding a description is optional, but a nice.
- Help text: Will default to 'leave a comma separated list of tags.
- Now go to admin/content/node and edit the eResource you added earlier. Notice that you now have a form field for keywords now. Enter a few and save.
What if we wanted to extend this and add additional info to eResource, e.g. a link, coverage information, selector contact, cost, & a tutorial about the resource. One way to do this is by adding this information directly to body itself, but this approach has problems.
Question: Class, what problems do you think arise by adding this information to the body?
Problems:
- Content providers would need to know what information is required for this CCK. What if someone didn't add a link for a eResource? It would be nice to force users to add certain fields & make sure they are properly formatted.
- If we wanted to sort by a field, it would be very hard to do with information in body. Mixed content is hard to parse! Structured content is where it's at!
- With mixed content we could show or hide fields based on access rules. Maybe we don't want the public to see certain fields.
- Making it pretty. Structured data gives us many more options on how we might want to theme the content, e.g. many more access points for CSS, etc.
Adding Additional Fields with CCK
CCK allows us to add different custom types of fields to content types in Drupal. For example, our eResource type will need a link, a selector contact, & other fields.
Every custom field added by cck offers us these same three choices to select:
- Kind of data it is
- Kind editing widget to capture the data on node form
- Kind of format for presentation or output
The CCK module comes with number of different types: number, text, node reference, user reference (e.g. eResource ->selector). In addition to these, 3rd party contributed moduals add lots more.
Hands on CCK
- Lets look at the content types before we turn CCK on. Go to admin/content/types.
- Now turn on the content module at admin/build/modules. Specifically, turn on Content, FileField, Node Reference, Number, Option Widgets (select lists, radio button), Text, Link, & User Reference and save.
- Go back to content type page. CCK adds 'manage fields' link.
- Click on manage fields of the eResource type. Notice CCK gives us the ability to Add a new field plus lets us re-order existing fields. This affects where those fields appear on the node form.
- Add New Field for url, select link.
- Add help text, "Please enter url for eResource", check required, leave 1 value.
- Save and create a new eResource. Notice how you have a url field now.
Adding a Number & Text Fields
- For the sake of this workshop, lets add 'cost' to the eResource. We obviously don't put the price of the eResource in the ERF, but I want to use a number field.
- Add New Field, add cost for Resource Type - look for select list, allowed value list. NOTE: Resource type could easily & might be better as a Taxonomy vocabulary.
Archival Collections and Primary Source Databases Article Databases Atlases, Maps and Gazetteers Biographical Sources Book and Film Review Databases Book and Text Collections (electronic) Dictionaries, Thesauri and Quotations Directories Dissertation and Thesis Databases Encyclopedias and Almanacs Government Information Sources - California/Regional Government Information Sources - Federal/US Government Information Sources - Foreign/International Handbooks and Manuals Image and Sound Databases Laws and Regulations Library Catalogs and Publication Lists News Databases Statistics and Numeric Data
Adding a User Reference Field
- Now lets add a Selector Contact which will be a user reference field. First lets create some users using the Devel Generate module. Go to admin/build/modules & turn on Devel Generate.
- Navigate to admin/generate/user & create 5 users.
- Lets now create a Selector & assign some users to it. Go to admin/user/roles and create selector. Then go to admin/user/user.
- Go back to admin/content/types and Manage fields for eResources. Add a new field called selector & choose user reference & autocomplete option.
- Make it required & check the selector role as the role that can be referenced.
- Save and now lets create a new eResource.
Adding a Node Reference
Now say we have a tutorial on one of the above databases and want to link the ERF to the tutorial. Ideally, the tutorial could be a file or embedded video on the site, but in this case we'll link out to an existing video.
- Lets create a tutorial type. Our tutorial will have a file upload & link field. A real tutorial content type probably should have an embedded media field for adding videos (requires account).
- Go to admin/content/types and Add a new content type. Call it tutorial and save.
- Manage fields on the new tutorial & add a File Field
- Fill in the settings: create help txt, under path settings add "pdf, doc, odf, rtf", under File size restrictions make 5M max. Save.
- Now add a tutorial. I'm adding a Lexis tutorial pdf. You can find this document here: (http://www.law.berkeley.edu/library/resources/lexisTutorial2007.pdf)[http://www.law.berkeley.edu/library/resources/lexisTutorial2007.pdf]
- We want to link the lexis tutorial to the lexis eResource entry. To do that we will use Node Reference. Go back to admin/content/types & Manage Fields on eResource.
- Add a Node Reference & check box/radio widget. Then check off tutorial on setting page & set 'number of values' to unlimited. This allows us to add multiple tutorials to a eResource record.
- Now edit the Lexis record & add the lexi tutorial.
CCK Display Fields
Let us control certain aspects of how a teaser & full node look.
- Go to Admin>Content Mgmt> Content types & manage fields on the eResource
- Look under display fields
- Make the labels display as inline
- Comma for cost display
- Save and preview
Additional CCK Modules
- Date module
- Filefield extension - image field
- Embedded media field - youtube
Field Level permissions
With CCK by default all fields visible to everyone. However, CCK ships with the 'content permission module' that changes that. If enabled, it will make all fields not viewable by any role. Its very granular. Suppose we only want to show the cost field to only selectors.
- Go to admin/build/modules and enable 'content permission'
- Now go to permission content permission mod allows for fine control over field