CCK For Code Junkies

CCK For Code CCK For Code Junkies Junkies DrupalCamp - DrupalCamp - ATL ATL Presented by: Geoff Maxey (cntlscrut) 1o.2.2 o1o


Slides from the session, "CCK For Code Junkies" that was presented at Drupalcamp ATL '10

Transcript of CCK For Code Junkies

Page 1: CCK For Code Junkies

CCK For Code CCK For Code JunkiesJunkiesDrupalCamp - DrupalCamp -

ATLATLPresented by: Geoff Maxey (cntlscrut)


Page 2: CCK For Code Junkies

This presentation will be available at:

Feel free to visit and download the slides.

Page 3: CCK For Code Junkies


To create a CCK field that contains multiple elements, interacts with 3rd party services, and can move/create content on a remote Drupal site.

Understand basic terminology of how CCK breaks down fields and widgets.

To cover the CCK field/widget API and how to implement it. Plus, cover the caveats and other roadblocks that may occur.

Page 4: CCK For Code Junkies


Title Gallery ID Featured Links Search Engine Keywords Selectable Results Embed Code from Remote Site

Page 5: CCK For Code Junkies

CCK Terms

CCK breaks things down into two different parts: Fields and Widgets

Fields – The namespace and container for data.

Widgets – The interaction space wherein we collect data from the user.

Page 6: CCK For Code Junkies

API Overview

Install: content_notify()

Field: hook_field_info() hook_field_settings() hook_field()

Page 7: CCK For Code Junkies

API Overview

Widget: hook_widget_info() hook_widget_settings() hook_widget()

Misc: hook_content_is_empty()

Page 8: CCK For Code Junkies

API Overview

AHAH: hook_menu() callback_js() (callback for AHAH actions)

Page 9: CCK For Code Junkies

Installation Functions

content_notify() -

Informs CCK of our field and which stage in Drupal's module install/uninstall process we are in.

Page 10: CCK For Code Junkies

Field Functions

hook_field_info() -

Provide basic info about our field including the machine name, display name, and description.

Page 11: CCK For Code Junkies

Field Functions

hook_field_settings() - Allows us to provide data specific to the set up of our field. We're looking at three different operations:

'form' – create a settings form for the field.

'save' – perform any special actions when saving the settings form.

'database columns' – define the schema structure for how our widget data will be saved in the database.

Page 12: CCK For Code Junkies

hook_field_settings – 'form'

Page 13: CCK For Code Junkies

hook_field_settings – 'save'

Page 14: CCK For Code Junkies

hook_field_settings – 'database columns'

Page 15: CCK For Code Junkies

Misc Functions

hook_content_is_empty() -

Perform any action if the field is empty.

Though this is declared an “optional” function, it is actually needed.

Page 16: CCK For Code Junkies

Field Functionshook_field($op, &$node, $field, &$items, $teaser, $page)

Defines how the field will actually store and display its contents.

Possible values for $op: 'delete' 'delete revision' 'insert' 'load' 'prepare translation' 'presave' 'sanitize' 'update' 'validate'

Page 17: CCK For Code Junkies


Page 18: CCK For Code Junkies

Widget Functions

hook_widget_info() -

Define basic info about our widget.

Page 19: CCK For Code Junkies


Here we can define our form elements using the FAPI! This is where the action happens.

Put on your 忍び装束 (shinobi shiozoku) it's Drupal Ninja Time!

(code available on site. Too big for slide.)