custom_formatters.api.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Custom Formatters module.
  5. */
  6. /**
  7. * Implements hook_custom_formatters_engine().
  8. */
  9. function hook_custom_formatters_engine_info() {
  10. $engines = array();
  11. $engines['MY_MODULE'] = array(
  12. 'label' => t('MY_MODULE'),
  13. 'callbacks' => array(
  14. 'settings form' => 'MYMODULE_engine_settings_form',
  15. 'render' => 'MYMODULE_engine_render',
  16. ),
  17. 'file' => drupal_get_path('module', 'MYMODULE') . '/engines/MYMODULE.inc',
  18. );
  19. return $engines;
  20. }
  21. /**
  22. * Implements hook_custom_formatters_defaults().
  23. */
  24. function hook_custom_formatters_defaults() {
  25. $formatters = array();
  26. $formatter = new stdClass;
  27. $formatter->disabled = FALSE; /* Edit this to true to make a default formatter disabled initially */
  28. $formatter->api_version = 2;
  29. $formatter->name = 'MYMODULE';
  30. $formatter->label = 'MYMODULE';
  31. $formatter->description = 'A PHP example formatter; Display a Thumbnail image linked to a Large image.';
  32. $formatter->mode = 'php';
  33. $formatter->field_types = 'image';
  34. $formatter->code = 'foreach (element_children($variables[\'#items\']) as $delta) {
  35. $item = $variables[\'#items\'][$delta];
  36. $thumbnail = theme(\'image_style\', array(\'style_name\' => \'thumbnail\', \'path\' => $item[\'uri\']));
  37. $large = image_style_path(\'large\', $item[\'uri\']);
  38. print l($thumbnail, file_create_url($large), array(\'html\' => TRUE));
  39. }';
  40. $formatters['example_php_image'] = $formatter;
  41. return $formatters;
  42. }