php.export.tpl.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. */
  5. ?>
  6. /**
  7. * Implements hook_field_formatter_info().
  8. */
  9. function <?php echo $module; ?>_field_formatter_info() {
  10. return array(
  11. '<?php echo $module; ?>_<?php echo $item->name; ?>' => array(
  12. 'label' => t('<?php echo $item->label; ?>'),
  13. 'field types' => array('<?php echo implode('\', \'', drupal_explode_tags($item->field_types)); ?>'),
  14. <?php if (isset($item->form)) : ?>
  15. 'settings' => array(
  16. <?php foreach ($item->form as $form_key => $element) : ?>
  17. '<?php echo $form_key; ?>' => <?php if (is_array($element['#default_value'])) : ?>
  18. array(
  19. <?php foreach ($element['#default_value'] as $key => $value) : ?>
  20. <?php echo is_integer($key) ? $key : "'{$key}'"; ?> => '<?php echo $value; ?>',
  21. <?php endforeach; ?>
  22. ),
  23. <?php else: ?>
  24. '<?php echo $element['#default_value']; ?>',
  25. <?php endif; ?>
  26. <?php endforeach; ?>
  27. ),
  28. <?php endif; ?>
  29. ),
  30. );
  31. }
  32. <?php if (isset($item->form)) : ?>
  33. /**
  34. * Implements hook_field_formatter_settings_summary().
  35. */
  36. function <?php echo $module; ?>_field_formatter_settings_summary($field, $instance, $view_mode) {
  37. $display = $instance['display'][$view_mode];
  38. $settings = $display['settings'];
  39. $summary = '';
  40. if ($display['type'] == '<?php echo $module; ?>_<?php echo $item->name; ?>') {
  41. <?php foreach (element_children($item->form) as $key) : ?>
  42. // <?php echo $item->form[$key]['#title'] ?>.
  43. $value = empty($settings['<?php echo $key; ?>']) ? '<em>' . t('Empty') . '</em>' : $settings['<?php echo $key; ?>'];
  44. $value = is_array($value) ? implode(', ', array_filter($value)) : $value;
  45. $summary .= "<?php echo $item->form[$key]['#title'] ?>: {$value}<br />";
  46. <?php endforeach; ?>
  47. }
  48. return $summary;
  49. }
  50. /**
  51. * Implements hook_field_formatter_settings_form().
  52. */
  53. function <?php echo $module; ?>_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  54. $display = $instance['display'][$view_mode];
  55. $settings = $display['settings'];
  56. <?php foreach (explode("\n", $item->fapi) as $line) : ?>
  57. <?php echo $line . "\n"; ?>
  58. <?php endforeach; ?>
  59. return $form;
  60. }
  61. <?php endif; ?>
  62. /**
  63. * Implements hook_field_formatter_view().
  64. */
  65. function <?php echo $module; ?>_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display) {
  66. $element = array();
  67. // Build variables array for formatter.
  68. $variables = array(
  69. '#obj_type' => $obj_type,
  70. '#object' => $object,
  71. '#field' => $field,
  72. '#instance' => $instance,
  73. '#langcode' => $langcode,
  74. '#items' => $items,
  75. '#display' => $display,
  76. );
  77. if (function_exists($function = "{$display['module']}_field_formatter_{$display['type']}")) {
  78. $element[0] = array(
  79. '#markup' => $function($variables),
  80. );
  81. }
  82. return $element;
  83. }
  84. /**
  85. * Field Formatter; <?php echo $item->label; ?>.
  86. */
  87. function <?php echo $module; ?>_field_formatter_<?php echo $module; ?>_<?php echo $item->name; ?>($variables) {
  88. <?php foreach (explode("\n", $item->code) as $line) : ?>
  89. <?php echo $line . "\n"; ?>
  90. <?php endforeach; ?>
  91. }