footnotes_field.module 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @file
  4. * Hooks and general logic for the Footnotes field module.
  5. */
  6. /**
  7. * Implements hook_ctools_plugin_api().
  8. */
  9. function footnotes_field_ctools_plugin_api($module, $api) {
  10. if (($module == 'ds' && $api == 'ds') || ($module == 'ds_extras' && $api == 'ds_extras')) {
  11. return array('version' => 1);
  12. }
  13. }
  14. /**
  15. * Implements hook_menu().
  16. */
  17. function footnotes_field_menu() {
  18. $items['admin/config/content/footnotes'] = array(
  19. 'title' => 'Footnotes',
  20. 'description' => 'Config page for footnotes fields/blocks',
  21. 'page callback' => 'drupal_get_form',
  22. 'page arguments' => array('_footnotes_field_admin_form'),
  23. 'access arguments' => array('administer footnotes fields'),
  24. 'file' => 'includes/footnotes_field.admin.inc',
  25. );
  26. return $items;
  27. }
  28. /**
  29. * Implements hook_permission().
  30. */
  31. function footnotes_field_permission() {
  32. return array(
  33. 'administer footnotes fields' => array(
  34. 'title' => t('Administer footnotes fields'),
  35. 'description' => t('Perform administration tasks for footnotes fields.'),
  36. ),
  37. );
  38. }
  39. /**
  40. * Implements hook_ds_fields_info().
  41. */
  42. function footnotes_field_ds_fields_info($entity_type) {
  43. $fields = array();
  44. $settings = _footnotes_field_get_settings();
  45. if (!empty($settings['content_types'])) {
  46. $content_types = array_keys(array_filter($settings['content_types']));
  47. // Only expose this field if there is at least one content type selected.
  48. if (!empty($content_types)) {
  49. $ui_limit = array();
  50. foreach ($content_types as $content_type) {
  51. $ui_limit[] = $content_type . '|*';
  52. }
  53. $fields['footnotes_field'] = array(
  54. 'title' => t('Footnotes (ds field)'),
  55. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  56. 'ui_limit' => $ui_limit,
  57. 'file' => drupal_get_path('module', 'footnotes_field') . '/ds/ds_footnotes_ui_field.inc',
  58. 'function' => '_footnotes_field_render',
  59. 'properties' => array(),
  60. );
  61. return array('node' => $fields);
  62. }
  63. }
  64. }
  65. /**
  66. * Implements hook_block_info().
  67. */
  68. function footnotes_field_block_info() {
  69. $blocks['footnotes'] = array(
  70. 'info' => t('Footnotes: node detail'),
  71. );
  72. return $blocks;
  73. }
  74. /**
  75. * Implements hook_block_view().
  76. */
  77. function footnotes_field_block_view($delta = '') {
  78. $block = array();
  79. switch ($delta) {
  80. case 'footnotes':
  81. $node = menu_get_object('node');
  82. $settings = _footnotes_field_get_settings();
  83. if ($node && !empty($settings['expose_block'])) {
  84. $block['subject'] = t('Footnotes');
  85. $block['content'] = array(
  86. '#prefix' => '<div id="footnotes-all">',
  87. '#markup' => NULL,
  88. '#suffix' => '</div>',
  89. '#attached' => array(
  90. 'js' => array(
  91. array(
  92. 'data' => drupal_get_path('module', 'footnotes_field') . '/js/footnotes_field.js',
  93. 'type' => 'file',
  94. ),
  95. ),
  96. 'css' => array(
  97. array(
  98. 'data' => drupal_get_path('module', 'footnotes_field') . '/css/footnotes_field.css',
  99. 'type' => 'file',
  100. ),
  101. ),
  102. ),
  103. );
  104. break;
  105. }
  106. }
  107. return $block;
  108. }
  109. /**
  110. * Fetches settings form admin page.
  111. *
  112. * @return array
  113. * The footnotes field settings.
  114. */
  115. function _footnotes_field_get_settings() {
  116. return variable_get('footnotes_field_settings', array());
  117. }