token.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @file
  4. * Token engine for Custom Formatters modules.
  5. */
  6. /**
  7. * Implements custom_formatters_engine_hook_theme_alter().
  8. */
  9. function custom_formatters_engine_token_theme_alter(&$theme) {
  10. $theme['custom_formatters_token_export'] = array(
  11. 'variables' => array(
  12. 'item' => NULL,
  13. 'module' => NULL,
  14. ),
  15. 'template' => 'token.export',
  16. 'path' => drupal_get_path('module', 'custom_formatters') . '/engines',
  17. );
  18. }
  19. /**
  20. * Settings form callback for Custom Formatters Token engine.
  21. */
  22. function custom_formatters_engine_token_settings_form(&$form, $form_state, $item) {
  23. $form['code']['#attributes']['class'][] = 'syntax-html';
  24. // Additional debugging modes.
  25. $form['preview']['options']['dpm'] = array(
  26. '#type' => 'container',
  27. );
  28. $form['preview']['options']['dpm']['html'] = array(
  29. '#type' => 'checkbox',
  30. '#title' => t('Output raw HTML (requires !devel module).', array('!devel' => l(t('Devel'), 'http://drupal.org/project/devel'))),
  31. '#default_value' => module_exists('devel'),
  32. '#disabled' => !module_exists('devel'),
  33. );
  34. $options = array();
  35. foreach (field_info_field_types() as $type => $field) {
  36. $options[$field['module']][$type] = $field['label'];
  37. }
  38. $form['field_types']['#type'] = 'select';
  39. $form['field_types']['#options'] = $options;
  40. unset($form['field_types']['#description']);
  41. }
  42. /**
  43. * Render callback for Custom Formatters Token engine.
  44. */
  45. function custom_formatters_engine_token_render($formatter, $obj_type, $object, $field, $instance, $langcode, $items, $display) {
  46. $element = array();
  47. foreach ($items as $delta => $item) {
  48. $text = $formatter->code;
  49. $token_data = array(
  50. $obj_type => $object,
  51. 'item' => $item,
  52. );
  53. drupal_alter('custom_formatters_token_data', $token_data, $text, $field);
  54. $element[$delta] = array(
  55. '#markup' => token_replace($text, $token_data, array('clear' => TRUE))
  56. );
  57. }
  58. return $element;
  59. }
  60. /**
  61. * Export callback for Custom Formatters Token engine.
  62. */
  63. function custom_formatters_engine_token_export($item, $module) {
  64. return theme('custom_formatters_token_export', array('item' => $item, 'module' => $module));
  65. }
  66. /**
  67. * Help callback for Custom Formatters Token engine.
  68. */
  69. function custom_formatters_engine_token_help() {
  70. return t('A HTML + Token Formatter utilizes Drupal Tokens and the Token module to create easy yet powerful formatters.') . "<br />\n"
  71. . t('All available Tokens can be navigated via the Tokens fieldset displayed below the Formatter field.');
  72. }