You are here

function safeword_field_formatter_view in Safeword 7

Same name and namespace in other branches
  1. 8 safeword.module \safeword_field_formatter_view()

Implements hook_field_formatter_view().

Three formatters are implemented.

  • safeword_human outputs an XSL-scrubbed version of the human text.
  • safeword_machine outputs the machine readable text, optionally displaying the human readable text in an HTML <acronym> tag.
  • safeword_both outputs the human readable text with the machine version in parenthesis.

File

./safeword.module, line 317
Provides a FieldAPI field type, widget, and several formatters for a combined human readable/machine name pair of values. Possible uses include automatic generation of editable pathauto segments, handy Views argument values, and impressing friends.

Code

function safeword_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {

    // This formatter simply outputs the field as text and with a color.
    case 'safeword_human':
      foreach ($items as $delta => $item) {
        $element[$delta]['#markup'] = filter_xss($item['human']);
      }
      break;
    case 'safeword_machine':
      foreach ($items as $delta => $item) {
        $element[$delta]['#markup'] = '<acronym title="' . filter_xss($item['human']) . '">' . filter_xss($item['machine']) . '</acronym>';
      }
      break;
    case 'safeword_machine_basic':
      foreach ($items as $delta => $item) {
        $element[$delta]['#markup'] = filter_xss($item['machine']);
      }
      break;

    // This formatter simply outputs the field as text and with a color.
    case 'safeword_both':
      foreach ($items as $delta => $item) {
        $element[$delta]['#markup'] = t("!human (!machine)", array(
          '!human' => filter_xss($item['human']),
          '!machine' => filter_xss($item['machine']),
        ));
      }
      break;
  }
  return $element;
}