Custom Field Formatters
Upcoming SlideShare
Loading in...5
×
 

Custom Field Formatters

on

  • 3,757 views

How and why to create your own

How and why to create your own

Statistics

Views

Total Views
3,757
Views on SlideShare
3,738
Embed Views
19

Actions

Likes
0
Downloads
30
Comments
2

4 Embeds 19

http://zivtech_redesign.dev.zivtech.com 9
http://www.zivtech.com 6
http://zivtech.local 3
http://zivtech_redesign.local 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

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

    theme_MODULE_formatter_MYFORMATTER($element)

    ??
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Custom Field Formatters Custom Field Formatters Presentation Transcript

  • Custom Field Formatters Design for Drupal, June 20, 2010
  • Jody Hamilton • Owner, Lead Developer at Zivtech • Drupal architect, developer, themer, site- builder, project manager, teacher and student • Jody Lynn on drupal.org
  • What is a Field Formatter?
  • Where are Field Formatters Used • Content Type “Display Options” • Views field options for CCK fields • Panels display options for CCK fields
  • Those Choices Don’t Cut it ... • When formatter options fail, many start to add complexity to node.tpl.php • Others turn to contemplate module
  • 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
  • Templating Node Content Breaks Drupal • If adding a new field or module requires you to edit node templates or contemplate, your site is broken
  • Baby Steps • Exclude certain fields from display, and then output only these separately • Avoid total obliteration of $content
  • Find the Formatter Theme Functions • Find the closest thing to what you want • Copy it • Tweak it
  • Start a Custom Module • .info file (meta information) • .module file (hook implementations and other functions)
  • Functions Needed • hook_field_formatter_info( ) • hook_theme( ) • theme_MODULE_MYFORMATTER_forma tter($element)
  • 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.
  • hook_theme • Describe your new theme function (or template) to Drupal • You must clear the theme registry when adding/changing a hook_theme implementation
  • Formatter Theme Function • $element is the parameter • $element[‘#item’] contains the meat • dpm to see what you’re working with
  • 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
  • Field Formatters in D7 • hook_field_formatter_info includes settings • hook_field_formatter_info_alter ! • hook_field_formatter_view (no theme function)