DrupalCamp 2011 -- Poutine Maker

43
Poutine Maker: Custom Fields in Drupal 7 Tavish Armstrong [email protected]

description

My DrupalCamp 2011

Transcript of DrupalCamp 2011 -- Poutine Maker

Page 1: DrupalCamp 2011 -- Poutine Maker

Poutine Maker: Custom Fields in Drupal 7

Tavish [email protected]

Page 2: DrupalCamp 2011 -- Poutine Maker

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

Page 3: DrupalCamp 2011 -- Poutine Maker

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

Page 4: DrupalCamp 2011 -- Poutine Maker

Custom fields: What are they?

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

Page 5: DrupalCamp 2011 -- Poutine Maker

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?

Page 6: DrupalCamp 2011 -- Poutine Maker
Page 7: DrupalCamp 2011 -- Poutine Maker

Colour picker widget

Page 8: DrupalCamp 2011 -- Poutine Maker

Alternative: field_collection

Exciting project!

Page 9: DrupalCamp 2011 -- Poutine Maker
Page 10: DrupalCamp 2011 -- Poutine Maker

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

Page 11: DrupalCamp 2011 -- Poutine Maker

hook_field_info()

Page 12: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_info()

Page 13: DrupalCamp 2011 -- Poutine Maker

hook_field_formatter_info()

Page 14: DrupalCamp 2011 -- Poutine Maker
Page 15: DrupalCamp 2011 -- Poutine Maker

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

Page 16: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 17: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 18: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 19: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 20: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 21: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 22: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 23: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_form()

Page 24: DrupalCamp 2011 -- Poutine Maker
Page 25: DrupalCamp 2011 -- Poutine Maker

hook_field_is_empty()

Page 26: DrupalCamp 2011 -- Poutine Maker

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

Page 27: DrupalCamp 2011 -- Poutine Maker

hook_field_schema()

Page 28: DrupalCamp 2011 -- Poutine Maker
Page 29: DrupalCamp 2011 -- Poutine Maker

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

Page 30: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_error()

Page 31: DrupalCamp 2011 -- Poutine Maker

hook_field_validate()

Page 32: DrupalCamp 2011 -- Poutine Maker

hook_field_widget_error()

Page 33: DrupalCamp 2011 -- Poutine Maker
Page 34: DrupalCamp 2011 -- Poutine Maker

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

Page 35: DrupalCamp 2011 -- Poutine Maker

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...);

Page 36: DrupalCamp 2011 -- Poutine Maker

hook_field_formatter_view()

Page 37: DrupalCamp 2011 -- Poutine Maker

poutine_maker_format_field()

Page 38: DrupalCamp 2011 -- Poutine Maker

poutine_maker_format_field()

Page 39: DrupalCamp 2011 -- Poutine Maker

poutine_maker_format_field()

Page 40: DrupalCamp 2011 -- Poutine Maker

The finished formatter

Page 41: DrupalCamp 2011 -- Poutine Maker

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

Page 42: DrupalCamp 2011 -- Poutine Maker

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

Page 43: DrupalCamp 2011 -- Poutine Maker

Questions?

Tavish Armstrong (tarmstrong)[email protected]