custom_formatters.module 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * @file
  4. * Contains core functions for the Custom Formatters module.
  5. */
  6. /**
  7. * Include additional files.
  8. */
  9. foreach (module_list() as $module) {
  10. if (file_exists($file = dirname(__FILE__) . "/includes/{$module}.inc")) {
  11. require_once $file;
  12. }
  13. }
  14. /**
  15. * Implements hook_permission().
  16. */
  17. function custom_formatters_permission() {
  18. return array(
  19. 'administer custom formatters' => array(
  20. 'title' => t('Administer Custom Formatters'),
  21. ),
  22. );
  23. }
  24. /**
  25. * Implements hook_menu().
  26. */
  27. function custom_formatters_menu() {
  28. $items = array();
  29. $items['admin/structure/formatters/settings'] = array(
  30. 'title' => 'Settings',
  31. 'page callback' => 'drupal_get_form',
  32. 'page arguments' => array('custom_formatters_settings_form'),
  33. 'access arguments' => array('administer custom formatters'),
  34. 'file' => 'custom_formatters.admin.inc',
  35. 'file path' => drupal_get_path('module', 'custom_formatters') . '/includes',
  36. 'type' => MENU_LOCAL_TASK,
  37. );
  38. $items['js/formatters/autocomplete'] = array(
  39. 'title' => 'Formatters autocomplete',
  40. 'page callback' => 'custom_formatters_autocomplete',
  41. 'access arguments' => array('administer custom formatters'),
  42. 'file' => 'custom_formatters.inc',
  43. 'file path' => drupal_get_path('module', 'custom_formatters') . '/plugins/export_ui',
  44. 'type' => MENU_CALLBACK,
  45. );
  46. return $items;
  47. }
  48. /**
  49. *
  50. */
  51. function custom_formatters_formatter_is_active($formatter) {
  52. $field_types = drupal_explode_tags($formatter->field_types);
  53. $field_info = field_info_fields();
  54. foreach (field_info_instances() as $bundles) {
  55. foreach ($bundles as $fields) {
  56. foreach ($fields as $field) {
  57. if (in_array($field_info[$field['field_name']]['type'], $field_types)) {
  58. foreach ($field['display'] as $display) {
  59. if ($display['type'] == "custom_formatters_{$formatter->name}") {
  60. return TRUE;
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }
  67. return FALSE;
  68. }
  69. /**
  70. *
  71. */
  72. function custom_formatters_crud_load($formatter) {
  73. $formatters = custom_formatters_crud_load_all();
  74. return isset($formatters[$formatter]) ? $formatters[$formatter] : NULL;
  75. }
  76. /**
  77. *
  78. */
  79. function custom_formatters_crud_load_all($flush_cache = FALSE) {
  80. $formatters = &drupal_static(__FUNCTION__, array());
  81. if (!$formatters || $flush_cache) {
  82. ctools_include('export');
  83. foreach (ctools_export_crud_load_all('formatters') as $formatter) {
  84. if (empty($formatter->disabled)) {
  85. $formatters[$formatter->name] = $formatter;
  86. }
  87. }
  88. }
  89. return $formatters;
  90. }