Field formatters

1,214 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,214
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Field formatters

  1. 1. Field/CCK Formatters“God has given you one face, and you make yourself another.” - Fortune cookie in my desk drawer Helior Colorado ihatespam@helior.info
  2. 2. What are Field Formatters?
  3. 3. What are Field Formatters?• Means to present field data in a displaying entity
  4. 4. What are Field Formatters?• Means to present field data in a displaying entity• Is pluggable
  5. 5. What are Field Formatters?• Means to present field data in a displaying entity• Is pluggable• Provides a layer of configurability
  6. 6. What are Field Formatters?• Means to present field data in a displaying entity• Is pluggable• Provides a layer of configurability• Is extendable via various methods
  7. 7. What are Field Formatters?• Means to present field data in a displaying entity• Is pluggable• Provides a layer of configurability• Is extendable via various methods• If done right, can be reused in any site
  8. 8. Defining a Field Formatter:hook_field_formatter_info()labeldescriptionfield typesmultiple valuessettings
  9. 9. Rendering a Field Formatter:hook_field_formatter_view()Return an array or renderablearrays – “N is the only number”
  10. 10. Providing configurations:hook_field_formatter_settings_form()Standard Form API stuff.Returning a new form element.This will help:$display = $instance[display][$view_mode];$settings = $display[settings];
  11. 11. Displaying configuration summary:hook_field_formatter_settings_summary()Output a string of whatever youthink is meaningful.
  12. 12. Pre-build formatter processing:hook_field_prepare_view()Custom data massaging goeshere.Rarely used.
  13. 13. Review the steps:
  14. 14. Review the steps:• Define formatter hook_field_formatter_info()
  15. 15. Review the steps:• Define formatter hook_field_formatter_info()• Return array of renderable arrays hook_field_formatter_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)
  16. 16. Review the steps:• Define formatter hook_field_formatter_info()• Return array of renderable arrays hook_field_formatter_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)• Optionally provide settings hook_field_formatter_settings_form($field, $instance, $view_mode, $form, & $form_state)
  17. 17. Review the steps:• Define formatter hook_field_formatter_info()• Return array of renderable arrays hook_field_formatter_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)• Optionally provide settings hook_field_formatter_settings_form($field, $instance, $view_mode, $form, & $form_state)• Optionally display settings summary hook_field_formatter_settings_summary($field, $instance, $view_mode)
  18. 18. Review the steps:• Define formatter hook_field_formatter_info()• Return array of renderable arrays hook_field_formatter_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)• Optionally provide settings hook_field_formatter_settings_form($field, $instance, $view_mode, $form, & $form_state)• Optionally display settings summary hook_field_formatter_settings_summary($field, $instance, $view_mode)• Optionally prepare data before build hook_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)
  19. 19. Review the steps:• Define formatter hook_field_formatter_info()• Return array of renderable arrays hook_field_formatter_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)• Optionally provide settings hook_field_formatter_settings_form($field, $instance, $view_mode, $form, & $form_state)• Optionally display settings summary hook_field_formatter_settings_summary($field, $instance, $view_mode)• Optionally prepare data before build hook_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)Useful helpers:
  20. 20. Review the steps:• Define formatter hook_field_formatter_info()• Return array of renderable arrays hook_field_formatter_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)• Optionally provide settings hook_field_formatter_settings_form($field, $instance, $view_mode, $form, & $form_state)• Optionally display settings summary hook_field_formatter_settings_summary($field, $instance, $view_mode)• Optionally prepare data before build hook_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, & $items, $display)Useful helpers:• field_info_formatter_types()• field_info_formatter_settings()• field_view_field()• field_view_value()
  21. 21. Ideas for Workshop★ HTML5 Audio playback controller ★ Lightbox-likegallery for images★ Email address “mailto:” link ★ Custom date from timestamp★ Link to Twitter account with selectable ★ Fully customizable link from a path styles

×