DrupalCamp 2011 -- Poutine Maker

Post on 14-Dec-2014

1.253 views 4 download

description

My DrupalCamp 2011

Transcript of DrupalCamp 2011 -- Poutine Maker

Poutine Maker: Custom Fields in Drupal 7

Tavish Armstrongtavish@evolvingweb.ca

Agenda

Custom fieldsWhat are they?What are they good for?

Info() hooks

Creating a widget

Creating a schema

Creating a validator

Creating a formatter

Demo

Resources

http://evolvingweb.ca/story/poutine-maker-introduction-field-api-drupal-7-part-1

http://drupal.org/sandbox/tarmstrong/1188140https://github.com/tarmstrong/poutine_maker

Custom fields: What are they?

• Custom fields are like a custom data type• You can also have a custom widgets, formatters, validation

Custom Fields: What are they good for?

• Drupal gives you text fields, date fields, etc.• It won't give you a colour field. Or a poutine

field.• You may want multi-value with a fieldset.• Fancy widgets?• Fancy formatting?• Fancy validation?

Colour picker widget

Alternative: field_collection

Exciting project!

Agenda

Custom fieldsWhat are they?What are they good for?

Info() hooks

Creating a widget

Creating a schema

Creating a validator

Creating a formatter

Demo

hook_field_info()

hook_field_widget_info()

hook_field_formatter_info()

Agenda

Custom fieldsWhat are they?What are they good for?

Info() hooks

Creating a widget

Creating a schema

Creating a validator

Creating a formatter

Demo

hook_field_widget_form()

hook_field_widget_form()

hook_field_widget_form()

hook_field_widget_form()

hook_field_widget_form()

hook_field_widget_form()

hook_field_widget_form()

hook_field_widget_form()

hook_field_is_empty()

Agenda

Custom fieldsWhat are they?What are they good for?

Info() hooks

Creating a widget

Creating a schema

Creating a validator

Creating a formatter

Demo

hook_field_schema()

Agenda

Custom fieldsWhat are they?What are they good for?

Info() hooks

Creating a widget

Creating a schema

Creating a validator

Creating a formatter

Demo

hook_field_widget_error()

hook_field_validate()

hook_field_widget_error()

Agenda

Custom fieldsWhat are they?What are they good for?

Info() hooks

Creating a widget

Creating a schema

Creating a validator

Creating a formatter

Demo

hook_field_formatter_view()

• Take all the saved field items (i.e. each $delta) and return a renderable array for each

$element[0] = array( first poutine item ... );$element[1] = array( second poutine item...);

hook_field_formatter_view()

poutine_maker_format_field()

poutine_maker_format_field()

poutine_maker_format_field()

The finished formatter

Agenda

Custom fieldsWhat are they?What are they good for?

Info() hooks

Creating a widget

Creating a schema

Creating a validator

Creating a formatter

Demo

Resources

http://evolvingweb.ca/story/poutine-maker-introduction-field-api-drupal-7-part-1

http://drupal.org/sandbox/tarmstrong/1188140https://github.com/tarmstrong/poutine_maker

Questions?

Tavish Armstrong (tarmstrong)tavish@evolvingweb.ca