Your SlideShare is downloading. ×
  • Like
Custom Field Formatters
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Custom Field Formatters

  • 3,015 views
Published

How and why to create your own

How and why to create your own

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Yes, you're right.
    Are you sure you want to
    Your message goes here
  • On slide 11, shouldn't the last bullet read:

    theme_MODULE_formatter_MYFORMATTER($element)

    ??
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads

Views

Total Views
3,015
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
31
Comments
2
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
















Transcript

  • 1. Custom Field Formatters Design for Drupal, June 20, 2010
  • 2. Jody Hamilton • Owner, Lead Developer at Zivtech • Drupal architect, developer, themer, site- builder, project manager, teacher and student • Jody Lynn on drupal.org
  • 3. What is a Field Formatter?
  • 4. Where are Field Formatters Used • Content Type “Display Options” • Views field options for CCK fields • Panels display options for CCK fields
  • 5. Those Choices Don’t Cut it ... • When formatter options fail, many start to add complexity to node.tpl.php • Others turn to contemplate module
  • 6. Devel’s Node Tabs • http://drupal.org/project/devel • Browse the raw data of the “loaded” and “rendered” node • dpm( ): a devel function to view data
  • 7. Templating Node Content Breaks Drupal • If adding a new field or module requires you to edit node templates or contemplate, your site is broken
  • 8. Baby Steps • Exclude certain fields from display, and then output only these separately • Avoid total obliteration of $content
  • 9. Find the Formatter Theme Functions • Find the closest thing to what you want • Copy it • Tweak it
  • 10. Start a Custom Module • .info file (meta information) • .module file (hook implementations and other functions)
  • 11. Functions Needed • hook_field_formatter_info( ) • hook_theme( ) • theme_MODULE_MYFORMATTER_forma tter($element)
  • 12. hook_field_formatter_info • Provide meta information about your new formatter: name, description, field types • Return an array of formatter(s) keyed by machine names.
  • 13. hook_theme • Describe your new theme function (or template) to Drupal • You must clear the theme registry when adding/changing a hook_theme implementation
  • 14. Formatter Theme Function • $element is the parameter • $element[‘#item’] contains the meat • dpm to see what you’re working with
  • 15. Sanitize your Output • The responsibility for sanitizing user- generated data falls on the themers and developers who output it with code. • When in doubt: check_plain or check_markup
  • 16. Field Formatters in D7 • hook_field_formatter_info includes settings • hook_field_formatter_info_alter ! • hook_field_formatter_view (no theme function)